Categories
JavaScript Answers

How to detect the onload event of a window opened with window.open with JavaScript?

Spread the love

Sometimes, we want to detect the onload event of a window opened with window.open with JavaScript.

In this article, we’ll look at how to detect the onload event of a window opened with window.open with JavaScript.

How to detect the onload event of a window opened with window.open with JavaScript?

To detect the onload event of a window opened with window.open with JavaScript, we set the popup’s onload method.

For instance, we write

const popup = window.open(location.href, "snapDown");
popup.onload = () => {
  alert("message one");
};

to call window.open to open a popup window that opens the location.href URL.

Then we set its onload property to a function that’s run when the popup window finishes loading.

Conclusion

To detect the onload event of a window opened with window.open with JavaScript, we set the popup’s onload method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *