How can I add a div to a popup in javascript?
I have created a popup using the following code in javascript;
window.open("http://google.com", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
I need to add the following dynamic div to this popup.
<div><img src="/images/img1.jpg" /></div>
the above div is dynamic because the src image will change according to the query string in the url
source to share
You cannot for security reasons. Due to the policy of the same origin (and google.com is definitely not your domain), you will not be allowed to access the DOM of the other window.
If the popup is from the same domain, the return value window.open
will be a link to the popup object window
: https://developer.mozilla.org/en/DOM/window.open
var popup = window.open("/relative path.html", ...);
popup.onload = function() { // of course you can use other onload-techniques
jQuery(popup.document.body).append("<div />"); // or any other dom manipulation
}
source to share
As Bergi said, there is no addition to the DOM from an external domain. But for the same domain (taken from here )
win=window.open('about:blank','instructions','width=300,height=200');
doc=win.document;
doc.open();
doc.write('<div id="instructions">instructions</div>');
doc.close();
//reference to the div inside the popup
//->doc.getElementById('instructions')
You can also see an example here .
source to share