[英]How to prevent popup using javascript?
無論如何我可以使用javascript來阻止來自另一個網站(iframe)的彈出窗口?
示例:我有一個網站,它 iframe 到其他幾個網站。 其中之一有這樣的彈出腳本:
<script type="text/javascript">
var popunder=new Array()
popunder[0]="http://www.target.com"
//Specify the width and height of new popunder window (in pixels).
var width = '700';
var height = '450';
//these are obvious variables. set "yes" or "no".
var p = 'scrollbars=yes, resizable=yes, toolbar=yes,' + 'menubar=yes, status=yes, location=yes, left=85, top=20, height=' + height + ',width=' + width;
// Load new PopUnder only once per browser session? (0=no, 1=yes)
// Putting 0 will cause the Popunder to load every time page is loaded
// Specifying 1 will cause it to load only once per session
var one_time=0
// That's it! Don't edit the code below unless you're really good. :-P //
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if the cookie exists
offset += search.length
//set the index of beginning value
end = document.cookie.indexOf(";", offset);
if (end == -1) // set the index of the end of cookie value
end = document.cookie.length;
returnvalue = unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('popunder')==''){
load_pop_power()
document.cookie="popunder=yes"
}
}
function load_pop_power(){
win2 = window.open(popunder[Math.floor(Math.random()*(popunder.length))], "bw", p)
win2.blur()
window.focus()
}
if (one_time==0)
load_pop_power()
else
loadornot()
</script>
前提是無法阻止此彈出窗口,並且用戶在 Firefox 或 IE 上的安全設置較低。
我有 ff。 網站上的 iframe: (iframe.php)
<iframe src="http://friend.com/pop.php"></iframe>
我應該在 iframe.php 頁面上做什么以防止彈出?
這是不可能的。 wdm 是對的。 但這里提供了更詳細的答案。
我很確定你想要做的事情是不可能的。
兩種選擇...
不,我不同意其他人的觀點,html5 有一個沙箱屬性,它控制通過 iframe 看到的內容或可以執行的操作。
只需在您的 Iframe 中添加以下屬性,它就會阻止彈出窗口“ sandbox="allow-scripts allow-forms allow-same-origin"
"
例如<iframe src="source of your iframe" sandbox="allow-scripts allow-forms allow-same-origin">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.