我的主页(Default.aspx)中有两个弹出窗口,如下所示:
apsx代码:
<div id="OffDiv">
</div>
<div id="TimerContainer">
<asp:Image ID="imgWhiteCircle" runat="server" ImageUrl="~/Images/WhiteCircle.png" />
<asp:Label ID="lblCountDown" runat="server" Text="60" Font-Bold="True" Font-Size="50px"
ForeColor="Black"></asp:Label>
</div>
css:
div#OffDiv
{
display: none;
position: fixed;
top: 0px;
right: 0px;
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
z-index: 90000;
background-color: black;
filter: alpha(opacity=30); /* internet explorer */
-khtml-opacity: 0.3; /* khtml, old safari */
-moz-opacity: 0.3; /* mozilla, netscape */
opacity: 0.3; /* fx, safari, opera */
}
div#TimerContainer
{
display: none;
position: absolute;
width: 110px;
height: 110px;
top: 200px;
left: 50%;
margin-left: -55px;
padding: 0px;
z-index: 90001;
}
#imgWhiteCircle
{
width: 110px;
}
#lblCountDown
{
position: absolute;
width: 70px;
height: 65px;
text-align: center;
top: 50%;
left: 50%;
margin-left: -35px;
margin-top: -32.5px;
}
JavaScript代码:
<script language="javascript" type="text/javascript">
$(function () {
var x = screen.availWidth;
$('div#OffDiv').css({ 'width': x });
var y = screen.availHeight;
$('div#OffDiv').css({ 'height': y });
$('div#OffDiv').css({ 'display': 'block' });
$('div#TimerContainer').css({ 'display': 'block' });
window.open('http://www.MyPoPUp1.com', '_blank', 'channelmode=no,directories=yes,location=no,resizable=yes,titlebar=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes', false);
window.open('http://www.MyPoPUp2.com', '_blank', 'channelmode=no,directories=yes,location=no,resizable=yes,titlebar=yes,menubar=no,toolbar=no,scrollbars=yes,status=yes', false);
window.focus();
var sec = $('#TimerContainer span').text()
var timer = setInterval(function () {
$('#TimerContainer span').text(--sec);
if (sec == 0) {
clearInterval(timer);
$('div#OffDiv').css({ 'display': 'none' });
$('div#TimerContainer').css({ 'display': 'none' });
}
}, 1000);
}); //End Of $(function ()
</script>
如您所见,在父窗口中有一个倒数计时器(从60秒开始)
在这个计时器中,我不想让我的用户关闭弹出窗口
我怎么能这样做?
提前致谢
答案 0 :(得分:1)
这样,无论打开的弹出窗口是否关闭,您都可以获得反馈。
var popup = window.open('http://www.google.com');
var timer = setInterval(function () {
if (popup.closed) {
alert('popup closed!');
clearInterval(timer);
}
}, 500);
此致