With javascript, I can open and close a popup window as follows.
var myWindow = window.open('http://example.org/');
// do things to window.
myWindow.close();
How do I manipulate the DOM elements of the page in the popup window before closing it? I have tried
myWindow.onready = function() {
myWindow.document.getElementById('someElementID').style.color = '#f00';
}
to no avail.
There is no event to let you know that the URL was loaded properly in the popup window. Only viable option is to set a timeout and then access the elements.
Like this:
var myWindow = window.open('./t6.html');
setTimeout(check, 3000);
console.log($('body', myWindow.document)); // This shows a blank "body"
function check() {
console.log($('body', myWindow.document)); // This shows the actual elements in the document
}
myWindow.close();
Here's a fiddle that demonstrates it working without your ready handler.
var myWindow = window.open('http://example.org/');
alert(myWindow)
// Alerts an HTMLDocument object
Like @jfriend00 mentioned in the comments, there's no ready event handler for a Window object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With