From: Joe Nine on
Scott Sauyet wrote:
> Joe Nine wrote:
>> Scott Sauyet wrote:
>>> Joe Nine wrote:
>> Before I'd trimmed the JS file down to being
>> just a document.write of an empty script tag, it was trying to load a JS
>> file that was getting a 404. Perhaps that was the problem. Anytime you
>> load either a blank src, or a src that results in a 404, the parent page
>> exhibits a weird XML or parse error in 3 out of the top 5 browsers.
>
> I don't think a 404 would be an issue. The issue is when the page
> referenced is not proper JS. If you use a blank "src" attribute, then
> it's requesting the current HTML file for the JS. That will certainly
> cause problems. If you requested "myDoc.html", it would probably also
> cause problems (assuming that file included HTML.)
>
> -- Scott

Thanks Scott (and Thomas in his reply). I hadn't realized (and find it
quite strange) that creating a tag with a blank src attribute would
request the current HTML file for the JS. How unusual, but at least it
explains it, especially when I think now of the original larger page.

It was loading a JS file, the name of which was in a variable. I was
allowing the variable to have a blank name thinking it wouldn't do any
harm, as I expected document.write'ing a script tag with no src would
simply create a script element that had nothing in it (no harm no foul).
Clearly that's wrong. I won't be doing that again.

This place is great. I doubt the answer to this particular peculiarity
is documented anywhere on the web.
From: Thomas 'PointedEars' Lahn on
Joe Nine wrote:

> Scott Sauyet wrote:
>> I don't think a 404 would be an issue. The issue is when the page
>> referenced is not proper JS. If you use a blank "src" attribute, then
>> it's requesting the current HTML file for the JS. That will certainly
>> cause problems. If you requested "myDoc.html", it would probably also
>> cause problems (assuming that file included HTML.)
>
> Thanks Scott (and Thomas in his reply). I hadn't realized (and find it
> quite strange) that creating a tag with a blank src attribute would
> request the current HTML file for the JS. How unusual, [...]

Only to the uninitiated, I am afraid. The value of the `src' attribute of
SCRIPT elements is specified to be of type URI⁽¹⁾, that is, a URI or URI-
reference as specified in RFC 3986⁽²⁾ (which obsoletes RFC 2396, which
updates RFC 1738, which is therefore referred in the HTML 4.01
Specification⁽³⁾).

An empty URI-reference is specified to be a same-document URI-reference.⁽⁴⁾
You can find that, for example, with the `action' attribute of FORM
elements, too, primarily if the document is dynamically generated by a
server-side application (like PHP).⁽⁵⁾

You're welcome :)


Regards,

PointedEars
___________
⁽¹⁾ <http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1>
⁽²⁾ <http://tools.ietf.org/html/rfc3986>
⁽³⁾ <http://www.w3.org/TR/REC-html40/types.html#type-uri>
⁽⁴⁾ <http://tools.ietf.org/html/rfc3986#section-4.4>
⁽⁵⁾ <http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.3>
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
From: David Mark on
On Jun 2, 3:40 pm, Scott Sauyet <scott.sau...(a)gmail.com> wrote:
> Joe Nine wrote:
> > Scott Sauyet wrote:
> >> Joe Nine wrote:
> >>> [ ... ]
> >>> document.write("<scr"+"ipt src=''><\/scr"+"ipt>");
> >>> [ ... ]
>
> >> I think the error is because of the empty src attribute in the
> >> generated SCRIPT element.
>
> >> It's requesting the current document as the source of the script
> >> element, and when it finds HTML instead of Javascript, it chokes.  If
> >> you said "src='abc'" does the error disappear?
>
> > No, the error was there also when I was loading a real file. But I have
> > to say, the file it was loading did itself also do a document.write of a
> > n empty script tag. The error wasn't inside the JS file though, it was
> > still in the parent page.
>
> Don't count on the error location being reported properly when scripts
> are including other scripts...
>
> > Before I'd trimmed the JS file down to being
> > just a document.write of an empty script tag, it was trying to load a JS
> > file that was getting a 404. Perhaps that was the problem. Anytime you
> > load either a blank src, or a src that results in a 404, the parent page
> > exhibits a weird XML or parse error in 3 out of the top 5 browsers.
>
> I don't think a 404 would be an issue.

A missing script will be problem if the server sends an error page.
From: Richard Cornford on
Scott Sauyet wrote:
>>> Joe Nine wrote:
>>>> [ ... ]
>>>> document.write("<scr"+"ipt src=''><\/scr"+"ipt>");
>>>> [ ... ]
<snip>
>
> Don't count on the error location being reported properly when
> scripts are including other scripts...
<snip>

While this is unfortunately true, and particularly true of (at least
older) IE browsers, it is still always the case the these error reports
are being create by a computer, with the inevitable underlying
mechanical logic that computers exhibit. My point being the while the
reported location may be incorrect the odds are that it result form the
application of rules and so the relative location may still be of use.
Take a location being reported as a line number, and the example code
above; if a carriage return were inserted before the - document.write -
line, and another after it, if the reported line number increased by one
then the error must be being reported for that single line, but if the
line number increased by two then that line cannot be responsible for
the error (and if the line number does not change then this code is
again not the location of the error). The actual line numbers are
discriminating here, but rather their relative values before and after
the insertion of the extra carriage returns.

Richard.

From: Joe Nine on
Thomas 'PointedEars' Lahn wrote:
> Joe Nine wrote:
>
>> Scott Sauyet wrote:
>> Thanks Scott (and Thomas in his reply). I hadn't realized (and find it
>> quite strange) that creating a tag with a blank src attribute would
>> request the current HTML file for the JS. How unusual, [...]
>
> Only to the uninitiated, I am afraid. The value of the `src' attribute of
> SCRIPT elements is specified to be of type URI⁽¹⁾, that is, a URI or URI-
> reference as specified in RFC 3986⁽²⁾ (which obsoletes RFC 2396, which
> updates RFC 1738, which is therefore referred in the HTML 4.01
> Specification⁽³⁾).
>
> An empty URI-reference is specified to be a same-document URI-reference.⁽⁴⁾
> You can find that, for example, with the `action' attribute of FORM
> elements, too, primarily if the document is dynamically generated by a
> server-side application (like PHP).⁽⁵⁾
>
> You're welcome :)
>
> Regards,
>
> PointedEars

Wouldn't the same logic apply to an IMG tag with src="" that's being
written using document.write? As far as can be observed, it doesn't seem
to suffer from the same behavior and simply sits there waiting for
someone to come along and set it's src attribute.