Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
how to detect window.open

I am trying to solve a scenario and let me try to explain using an example. I have a script which tries to open a new url using window.open method. This script triggers a window open after 5 sec without any click event from the user. What I would like to do is .. capture the window open method. Is there any function available like addEventListener to capture window open method? I would like to track a window.open which was not initiated by user action.

Thanks Lynn

setTimeout(function(){
window.open(url,name);
}, 5000); 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can replace it

NOTE: window.open does not work at stackoverflow due to sandboxing Also a window.open not triggered by a user action will likely be suppressed by the browser

const saveOpen = window.open;
window.open = function(url,windowName,parms) {
  console.log("triggered",url);
  saveOpen(url, windowName || "",parms || "")
};
const url = "https://stackoverflow.com", windowName="myWin"
setTimeout(function(){
  window.open(url,windowName);
}, 1000); 

As mentioned in How to call a function of another window in javascript? you could attach a load event listener to the window:

const loaded = function(str) { console.log(str) },
url = "https://stackoverflow.com", windowName="myWin";
setTimeout(function(){
  const w = window.open(url,windowName);
  if (w) w.addEventListener('load',function() { loaded(url)})
  else console.log('sorry, not allowed'); // this of course can be a call to whatever
}, 1000);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!