我正在嵌入具有退出弹出窗口的页面。当您关闭页面时,它会自动启动一个弹出窗口。
如何在退出时禁用来自 iframe 的弹出窗口?
我正在嵌入具有退出弹出窗口的页面。当您关闭页面时,它会自动启动一个弹出窗口。
如何在退出时禁用来自 iframe 的弹出窗口?
如果您想阻止弹出式广告或来自您在 IFRAME 中显示的网站的内容 - 这相当容易。
制作iframe 指向的framefilter.php和javascriptfilter.php 。您可以对其进行修改以满足您的需求,例如 onload blah blah 等。但按原样 - 它对我来说已经工作了很长一段时间。希望能帮助到你。
将您的标准 IFRAME HTML 替换为:
<IFRAME SRC="http://www.yourdomainhere.com/framefilter.php?furl=http://www.domainname.com" WIDTH=1000 HEIGHT=500>
If you can see this, your browser doesn't
understand IFRAMES. However, we'll still
<A HREF="http://www.domainname.com">link</A>
you to the page.
</IFRAME>
帧过滤器.php
<?php
//Get the raw html.
$furl=trim($_GET["furl"]);
$raw = file_get_contents($furl);
$mydomain="http://www.yourdomainhere.com/";
//Kill anoying popups.
$raw=str_replace("alert(","isNull(",$raw);
$raw=str_replace("window.open","isNull",$raw);
$raw=str_replace("prompt(","isNull(",$raw);
$raw=str_replace("Confirm: (","isNull(",$raw);
//Modify the javascript links so they go though a filter.
$raw=str_replace("script type=\"text/javascript\" src=\"","script type=\"text/javascript\" src=\"".$mydomain."javascriptfilter.php?jurl=",$raw);
$raw=str_replace("script src=","script src=".$mydomain."javascriptfilter.php?jurl=",$raw);
//Or kill js files
//$raw=str_replace(".js",".off",$raw);
//Put in a base domain tag so images, flash and css are certain to work.
$replacethis="<head>";
$replacestring="<head><base href='".$furl."/'>";
$raw=str_replace($replacethis,$replacestring,$raw);
//Echo the website html to the iframe.
echo $raw;
?>
javascriptfilter.php
<?php
//Get the raw html.
$jurl=trim($_GET["jurl"]);
$raw = file_get_contents($jurl);
//Note, if trickyness like decode detected then display empty.
if(!preg_match("decode(", $raw)){
//Kill anoying popups.
$raw=str_replace("alert(","isNull(",$raw);
$raw=str_replace("window.open","isNull",$raw);
$raw=str_replace("prompt(","isNull(",$raw);
$raw=str_replace("Confirm: (","isNull(",$raw);
//Echo the website html to the iframe.
echo $raw;
}
?>
很老的问题,但我想我会提供一个更新的解决方案,因为这是谷歌的最佳结果。
如果要阻止 iframe 打开窗口,可以在 iframe 上使用新的 HTML5“沙盒”属性。
https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe
这应该可以防止它做任何事情(除了运行 javascript 可能需要页面正常运行):
<iframe sandbox="allow-scripts" src="your/url/here"></iframe>
实际上,这是可能的。至少在很多情况下。通常,iframe 中的代码会运行类似于top.window.open(...)
打开弹出窗口的操作。您可以重新定义 window.open 方法,使其仍然存在,但不会打开窗口。例如:
` window.alias_open = window.open;
window.open = function(url, name, specs, replace) { // 什么都不做,或者做一些聪明的事... } `
如果您仍然希望打开一些弹出窗口,您可以将 url 中的 url 列入白名单window.open
,并alias_open
根据需要调用。
我不认为这是可能的。
我看到的唯一可能性本质上是非技术性的:与在 iframe 中运行该站点的人核实他们是否可以为您制作一个特殊页面,一个没有此类 onunload 弹出窗口的页面。在大多数情况下,要么
在 IFrame 元素上设置沙箱属性应该可以工作。
我不确定这是否可行,但您可以尝试双 Iframing。在免费的博主帐户中 iframe 网站,然后使用延迟加载代码 iframe 博主帐户。所以弹出会在页面加载之前发生,让我知道它是否有效。
使用现代浏览器- 它们都具有不错的弹出窗口阻止功能