Reputation: 2577
I have a JS script that opens a pdf in a new tab.
var newWindow = window.open("url", "docWindow");
Is it possible to check if that document has loaded without running a script on that window, to check the readyState
status of that document from the original tab?
Upvotes: 2
Views: 4206
Reputation: 51
After struggling I found the best solution from jquery webpage.
https://learn.jquery.com/using-jquery-core/document-ready/
$( window ).on( "load", function() {
console.log( "window loaded" );
});
After the entire window is loaded you can run your code. Hope this helps someone in future.
Upvotes: 0
Reputation: 167220
I believe, this should be possible with window
this way:
newWindow.onload = function () {
// Do stuff after window is loaded.
};
For the ReadyState, you can use the window.document
:
newWindow.document.readyState;
Set an event handler on the readyState
and call your opening function.
newWindow.document.onreadystatechange = function () {
if (newWindow.document.readyState === "complete") {
// Call the code.
}
}
Upvotes: 2