Re: ISSUE-29: how is uri parameter of the open() method resolved

Anne van Kesteren wrote:
> 
> On Fri, 24 Feb 2006 18:34:52 +0100, Maciej Stachowiak <mjs@apple.com> 
> wrote:
>> In Safari, and I believe also in Firefox and Internet Explorer, if the 
>> URI parameter is a relative URI reference, it is resolved against the 
>> window.location.href of the Window object currently executing script, 
>> which may or may not be the same as the one used to create the 
>> XMLHttpRequest object.
> 
> Firefox uses document.baseURI from what I recall. (Probably because of 
> <base> and author expectations...)

What we do is that we use window.document.baseURI, most likely for IE
compat wrt interaction with <base>.

It is worse if multiple documents are calling each other and there are
XMLHttpRequest objects involved. Then it is more or less unpredictable
in mozilla.

What we should do is that we should define exactly which base uri to
use. I can see two options:
1. Either use the window.document.baseURI at creation time of
    the XHR. I.e. the baseURI is stored at creation time and then
    used whenever .open is called.
2. Get window.document.baseURI when .open is called

Additionally, there is the question of which window to use when a
function in window A calls a function in window B, which creates and
opens an XHR. Consider:

file1.html:
<iframe src="file2.html" id="frame"></iframe>
<script>
document.body.onload = function() {
   document.getElementById('frame').contentWindow.doIt('./test.xml');
}
</script>


file2.html:
<script>
function doIt(uri) {
   xhr = new XMLHttpRequest();
   xhr.open('GET', uri, false);
   return xhr.responseXML;
}
</script>


Should the uri "./test.xml" be resolved against "file1.html" or
'file2.html'. This is a real issue and something that people actually
do. There is no way to always get this 'right' since the uri-string
could have just as well come from file2.html.

In mozilla we actually use file1.html as baseURI, though I would argue
that we should use file2.html.

/ Jonas

Received on Tuesday, 28 February 2006 21:48:51 UTC