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)
- 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
2 Answers
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');
}