我发现关闭弹出窗口的一个方便技巧 [英] A handy trick I discovered for closing popups

查看:71
本文介绍了我发现关闭弹出窗口的一个方便技巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有人离开

我的页面时,我正在寻找一种弹出窗口的方法,但当他们点击刷新或返回时没有出现

按钮在浏览器上。因为使用onUnload =" ..."在body标签中

导致窗口出现在你点击刷新或后退按钮时,

没有做我想要的。


在谷歌搜索了很多天后,我从来没有找到答案

如何做到这一点。我以为我可以让每个页面打开弹出窗口

onUnload,但是然后每个页面关闭窗口onLoad,所以

窗口只有在你实际退出时仍然可见我的整个网站。

问题是,我没有想要关闭窗口的

页面中窗口对象的句柄。我尝试在一个

cookie中传递句柄,但这也没有用。


我的解决方案,我在其他任何地方都看不到以前,像

这样工作:


每一页(它们都是php)都包含相同的标题,其中包含此代码

in它:


var exit = true;

<?php

$ popstuff = file_get_contents(" _popstuff.txt" );

$ values = explode(" |",$ popstuff);

$ usepop = $ values [0];

if($ usepop!=" on"){

echo(" exit = false; \ n"); //关闭弹出窗口

}

?>

函数offerWindow(){

if(退出) ){

offerPop = window.open(''_ offer.php'',

''offer'',''width = 425,height = 298,resizable = 0,toolbar = 0,location = 0,directories = 0,status = 0,menubar = 0,scro llbars = 0'');

offerPop.blur();

window.focus();

}

}

函数noExit(){

exit = false ;

}

函数closeOffer(){

offerPop = window.open(''_ offer.php'',

''offer'',''width = 0,height = 0,resizable = 0,toolbar = 0,lo cation = 0,directories = 0,status = 0,menubar = 0,scrollba rs = 0'' );

offerPop.close();

}

//结束 - >

< / script>

< / head>

< body onUnload =" offerWindow();" onLoad =" closeOffer();">


现在发生的事情是,如果你离开页面,它会打开弹出窗口,但是你甚至还要等到
看到它,下一页关闭它(通过窗口名称

而不是句柄)。如果你关闭浏览器,或者离开整个网页
页面,那么弹出窗口仍然存在。如果有一条路径你想要从没有显示弹出窗口的网站中取出

onClick =" noExit()"到链接,它关闭弹出窗口。通常,网站内页面之间的链接将包括

noExit()打电话让弹出窗口永远不会显示出来。但是弹出窗口出现在浏览器刷新或后退按钮上的问题就消失了。


--gary

I was looking for a way to have a popup window appear when someone left
my page, but not have it appear when they hit the refresh or back
buttons on the browser. Since using onUnload="..." in the body tag
causes the window to appear when you hit the refresh or back buttons,
that didn''t do what I wanted.

After doing Google searches for many days I never did find an answer
for how to do this. I thought I could have each page open the popup
onUnload, but then also have each page close the window onLoad, so the
window only stays visible if you actually exit from my whole website.
The problem is, I didn''t have the handle to the window object in the
page that wanted to close the window. I tried passing the handle in a
cookie, but that didn''t work either.

My solution, which I haven''t seen anywhere else before, works like
this:

Every page (they are php) includes the same header which has this code
in it:

var exit = true;
<?php
$popstuff = file_get_contents("_popstuff.txt");
$values = explode("|",$popstuff);
$usepop = $values[0];
if ($usepop!="on") {
echo("exit = false;\n"); // turn off popup window
}
?>
function offerWindow() {
if ( exit ) {
offerPop=window.open(''_offer.php'',
''offer'',''width=425,height=298,resizable=0,toolbar= 0,location=0,directories=0,status=0,menubar=0,scro llbars=0'');
offerPop.blur();
window.focus();
}
}
function noExit() {
exit = false;
}
function closeOffer() {
offerPop=window.open(''_offer.php'',
''offer'',''width=0,height=0,resizable=0,toolbar=0,lo cation=0,directories=0,status=0,menubar=0,scrollba rs=0'');
offerPop.close();
}
// End -->
</script>
</head>
<body onUnload="offerWindow();" onLoad="closeOffer();">

Now what happens is if you leave the page it opens the popup, but
before you even get to see it, the next page closes it (by window name
instead of by handle). If you close the browser, or leave the whole web
page then the popup remains. If there is a path you wish to take out of
the site that does not show the popup then just include
onClick="noExit()" to the link and it turns off the popup. Normally the
links that go from page to page within the website will all include the
"noExit()" call so the popup never even shows up. But the problem where
the popup shows up on browser refresh or back buttons just goes away.

--gary

推荐答案

popstuff = file_get_contents(" _popstuff.txt");
popstuff = file_get_contents("_popstuff.txt");


values = explode(" | ",
values = explode("|",


popstuff);
popstuff);


这篇关于我发现关闭弹出窗口的一个方便技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆