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.