disallow window open in javascript

后端 未结 2 1014
深忆病人
深忆病人 2021-01-05 06:40

How can I disable window.open() using html, javascript, jQuery...?
I mean block any window open attempt, making \"not-working\" all existing window.open() f

相关标签:
2条回答
  • 2021-01-05 07:37
    //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!
    };
    
    0 讨论(0)
  • 2021-01-05 07:37

    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 讨论(0)
提交回复
热议问题