最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

iframe - disallow window open in javascript - Stack Overflow

programmeradmin5浏览0评论

How can I disable window.open() using html, javascript, jQuery...?
I mean block any window open attempt, making "not-working" all existing window.open() functions.
Which are the best ways to do it? (working also in case of iframes)

How can I disable window.open() using html, javascript, jQuery...?
I mean block any window open attempt, making "not-working" all existing window.open() functions.
Which are the best ways to do it? (working also in case of iframes)

Share Improve this question edited May 2, 2015 at 5:11 user663031 asked May 2, 2015 at 4:42 neoDevneoDev 3,0493 gold badges38 silver badges67 bronze badges 2
  • Not sure if it's possible. Can't just disable JS altogether? – Huey Commented May 2, 2015 at 4:50
  • websites that disable browser features are a blight. if you were hosting my website in an iframe on your website and disabled window.open from working in my code, we wouldn't be working together long.... – Claies Commented May 5, 2015 at 3:17
Add a ment  | 

2 Answers 2

Reset to default 9
//for iframes:
$.each($('iframe'), function() {
    this.contentWindow.open = function (url, windowName, windowFeatures) {
        //iframe window.open caught!
    };
});

//for window:
window.open = function (url, windowName, windowFeatures) {
    //window.open caught!
};

You'd be polluting the global namespace, but you could simply override the window.open method...

window.open = function (url, windowName, windowFeatures) {
    console.log('not opening a window');
} 
发布评论

评论列表(0)

  1. 暂无评论