Reputation: 164
I would like to load yahoo.com in a new window using the window.open function. Then, fill in the search field and submit the search form using jQuery.
For some reason the following code doesn't work:
var yhooWin;
var yhooDoc;
function openYahooWindow() {
yhooWin = window.open("http://yahoo.com","ywin","width=1050,height=750");
yhooWin.focus();
}
openYahooWindow();
yhooDoc = yhooWin.document;
$(yhooDoc).ready(function () {
$(yhooDoc).contents().find("#p_13838465-p").val("gangnam style");
$(yhooDoc).contents().find(".searchsubmit").trigger("click");
});
Where am I going wrong?
Upvotes: 1
Views: 1817
Reputation: 1054
You can't control a new window using another pages javascript.
For example:
Page1.html uses window.open
to open yahoo.com
Page1.html can not take any action on yahoo.com
Upvotes: 0
Reputation: 207511
You can not access the contents of a different domain because of the same origin policy. Look at the error console, you will see the error message.
If you controlled the other domain, you could look into CORS. Another option is a serverside proxy. And another option is a service like Yahoo Pipes and make JSONP calls.
Upvotes: 1