Reputation:
I have a function which I called whenever a new tab opens from window.open as I have overrode that function. Also,
I have attached a function on document.onclick event I need that function to be a pause or stop whenever window.open function runs.
I know the event.stopPropagation(); is used for achieving this but in the function, it's not working as event argument couldn't pass.
window.open = function(open) {
return function(url) {
console.log("url", url);
// need to works here event.stopPropagation();
return open.call(window, url);
};
}(window.open);
document.onclick = clickListener;
function clickListener() {
console.log("click");
};
function openLink(){
window.open('https://www.google.com')
}
<button onclick="openLink()">open link</button>
Upvotes: 3
Views: 629
Reputation: 54
var staticVar = false;
window.open = function(open) {
return function(url) {
console.log("url", url);
staticVar = true;
// need to works here event.stopPropagation();
return open.call(window, url);
};
}(window.open);
document.onclick = clickListener;
function clickListener() {
if(!staticVar) {
console.log("click")
}
staticVar = false;
};
function openLink() {
window.open('https://www.google.com');
}
<button onclick="openLink()">open link</button>
Upvotes: 0
Reputation: 647
Event object will be available on window. You can try following:
window.open = (function(open) {
return function(url) {
window.event.stopPropagation();
console.log("url", url);
// need to works here event.stopPropagation();
return open.call(window, url);
};
})(window.open);
Upvotes: 3