Reputation: 2907
I'm going to use postMessage
method to send a text to an opened window right after opening the window on ther origin.
I tried the following:
let ref = window.open("<address>", "name", "resizable,scrollbars,status");
ref.postMessage("Some Message");
A listener is defined on the other page to get the posted message, but it doesn't work, since the posted message is being sent before the page loading is completed.
Is there any way to check that the page on the opened window is fully loaded?
Upvotes: 1
Views: 93
Reputation: 35513
You can implement an "handshake" mechanism, so it would be like,
window.addEventListener('message', () => {})
)parent.window.opener.postMessage('ImALive', '<url address of parent>')
)Something like that.
Upvotes: 3
Reputation: 1877
Have you tried $(window).load(function(){})
.
You can write your code in this event and then try it.
This question on SO might help.
Upvotes: 0
Reputation: 75
You can try simple Javascript trick as below to see if DOM is loaded, you can use this function which will get execute after DOM gets load.
document.addEventListener('DOMContentLoaded', function(event) {
//alert("hello"); your code
})
Upvotes: 0