I want to do something like this:
var w = window.open("javascript: makeAnAjaxRequest();");
My question is, would the Ajax request (executed once the new window opens) be considered a cross-site request? Does the same-domain policy apply to the original domain whose page created the window?
In resposne to some of your comments:
someAjaxFunction() just has to make an Ajax request and be able to operate on the result. I understand that the function has to be defined in the window I am opening. No problem; I have a minified ajax function that I am using which I can inject into the URL as well. The point is to see what the limitations are of the request; i.e., under which domain will the same-domain policy be applied to?
Some info from google: http://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_DOM_access
Info from Mozilla
So your answer is
Otherwise, you are restricted.
EDIT – real answer
window.open('javascript:doFunction()')would not do anything except open a new blank window which fails to do anything becausedoFunctionis not defined. It needs to be defined in the same window.Sidenote I can do the same-origin xhr request by injecting the ajax into the url directly, but it’s still susceptible to the same-domain policy.
It fails in Firefox. And I haven’t tested it in MSIE yet. But
Tests:
(failure) Chrome 7 ( console ) from http://stackoverflow.com:80
(success) Chrome 7 ( console ) from http://stackoverflow.com:80
(failure) Firefox 3.6 ( console ) from http://stackoverflow.com:80
(success) Firefox 3.6 ( console ) from http://stackoverflow.com:80
(failure) Firefox 3.6 ( console ) from http://stackoverflow.com:80
(success) Firefox 3.6 ( console ) from http://stackoverflow.com:80