RESOLVED FIXED 4343
XMLHttpRequest doesn't work in a JavaScript-created window
https://bugs.webkit.org/show_bug.cgi?id=4343
Summary XMLHttpRequest doesn't work in a JavaScript-created window
Jacob Weber
Reported 2005-08-08 18:14:33 PDT
The following page creates an XMLHttpRequest object, makes a request to Google, and displays its progress in alerts: <html><body><script type="text/javascript"> var req = new XMLHttpRequest(); req.onreadystatechange = result; req.open("GET", "http://www.google.com", true); req.send(); function result() {alert(req.responseText);} </script></body></html> This works fine in Safari. However, it's also possible to use JavaScript to write to a new browser window, and it can even write JavaScript into the window. This also works in Safari. However, if we use JavaScript to write the above code, the XMLHttpRequest never gets sent. For example: <html><body><script type="text/javascript"> winRef=window.open(); winRef.document.writeln("<html><body><script type=\"text/javascript\">"); winRef.document.writeln("var req = new XMLHttpRequest();"); winRef.document.writeln("req.onreadystatechange = result;"); winRef.document.writeln("req.open(\"GET\", \"http://www.google.com\", true);"); winRef.document.writeln("req.send();"); winRef.document.writeln("function result() {alert(req.responseText);}"); winRef.document.writeln("<\/script></body></html>"); winRef.document.close(); </script></body></html>
Attachments
test case (366 bytes, text/html)
2005-12-23 02:55 PST, Alexey Proskuryakov
no flags
test case for landing (2.98 KB, patch)
2009-03-03 02:59 PST, Alexey Proskuryakov
aroben: review+
Alexey Proskuryakov
Comment 1 2005-12-23 02:53:40 PST
The problem here is that the created document has an about:blank URL, so it isn't considered a local file, and isn't allowed to use XMLHttpRequest.
Alexey Proskuryakov
Comment 2 2005-12-23 02:55:12 PST
Created attachment 5244 [details] test case Safari: winRef.document.URL: file:///Users/ap/Desktop/4343.html document.URL: about:blank Firefox 1.5: winRef.document.URL: about:blank document.URL: file:///Users/ap/Desktop/4343.html
Alexey Proskuryakov
Comment 3 2006-01-02 02:59:50 PST
See also: bug 5292.
Alexey Proskuryakov
Comment 4 2009-03-03 02:50:46 PST
This was fixed in <http://trac.webkit.org/projects/webkit/changeset/34506> and related check-ins. Looks like this exact scenario doesn't have a test yet, so I'll make a patch to land a test for XHR from a pop-up window.
Alexey Proskuryakov
Comment 5 2009-03-03 02:59:37 PST
Created attachment 28218 [details] test case for landing
Adam Roben (:aroben)
Comment 6 2009-03-03 07:26:37 PST
Comment on attachment 28218 [details] test case for landing r=me
Alexey Proskuryakov
Comment 7 2009-03-03 08:46:59 PST
Committed revision 41382.
Note You need to log in before you can comment on or make changes to this bug.