Can i modify HTML DOM of an external URL loaded using window.open?
Suppose i have a page at : www.mydomain.com
when the user clicks on a button, it opens a n开发者_StackOverflow社区ew window using :
newWin = window.open("https://www.otherdomain.com","a","height=800,width=1000");
Now, i want to modify some fields on the page. Specifically, the new window displays a form and i want to be able to autofill the form using the details the user entered on mydomain.com
Is this possible ?
If yes, then that beings me to another question :
Using jQuery, how do i invoke the ready() eventhandler for the newly loaded page ?
EDIT: So, as most guys pointed out here. Its the same origin policy. Can i do it using any other way. Like display the other page in frames ?
you dont really have much control over the new pages DOM since it is on another domain,
what you do have control over is when u close it:
so lets say u want to close it in 1 minute, on the main window u can do now:
setTimout(function(){newWin.close()},60000)
but otherwise i dont belive there is much you can do aside from sending javascript calls to the new window by doing:
newWin.open('javascript:alert("Hello");');
Well there are a couple of ways :-?
newWin = window.open("https://www.otherdomain.com","a","height=800,width=1000");
$(newWin).ready(function(){
alert('New page has '+newWin.document.forms.length+' forms.');
});
精彩评论