views:

162

answers:

5

There exist other ways of linking to JS, apart from this (the usual)..

<script src="myscript.js" type="text/javascript"></script>

...that utilize other quote types:

<script src=&#34;myscript.js&#34; type=&#34;text/javascript&#34;></script>

Are these widely supported in modern browsers, and older browsers in use, such as IE6? Basically is it safe to use this method, just as you would use the regular double-quote method?


Edit: The HTML4 spec seems to allow it, but is it well supported in practical reality?

3.2.2 Attributes

  Authors may also use numeric character references to represent
  double quotes (&#34;) and single quotes (&#39;).

  For double quotes authors can also use the
  character entity reference &quot;.
A: 

Just out of curiosity. Why would you want to use the encoded variants? In most of the text editors it will break the formatting. For me that would be very annoying.

Joop
A: 

You should stick with the double quotes - othewise the attribute might not be correctly read.

Sohnee
"Might not be correct" ... so I'm to take your word for it and go away?
Jenko
+5  A: 

Using &#34; instead of " is simply wrong, it doesn't have the same meaning within the SGML and XML specifications. Argument values of elements should use either single (') or double quotes ("). In the old SGML specification this element

<foo bar=&#34;quux&#34; />

could be read as an element with the name foo, and attribute named bar with the value "quux". However, the standard defines that unquoted attribute values should not include escaped characters. And this element

<foo bar="quux" />

should be read as an element with the name foo, and attribute named bar with the value quux without the quotes. This is because in SGML the quotes are optional, and everything up to the next space will be used as the value for the attribute.

XML requires quotes.

elmuerte
So is this okay in HTML and XHTML? Will it be sucessfully parsed and understood?
Jenko
Or should I write it without any quotes like this: <script src=/path/to/script.js .. >
Jenko
For HTML either use <script src="..." >, <script src='...' > or <script src=... > . But the latter is strongly discouraged. For XHTML only the first two possibilities are allowed.
elmuerte
David Dorward
No its not an error -- "Authors may also use numeric character references to represent double quotes" -- http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
Jenko
But in that context, it is an attribute value delimiter, not a double quote.
David Dorward
@elmuerte Since all content-types include a "/" character and since "/" characters may not appear in attribute values that are not delimited by single or double quote marks - the third option is not allowed.
David Dorward
We don't think so : http://stackoverflow.com/questions/963679/do-browsers-widely-support-numeric-quotes-in-attributes
Jenko
A: 
<script src=myscript.js></script>

is valid in HTML5 and supported by every significant browser.

Grégoire Cachet
Well it has to be an absolute link.. so I'd like: src=/path/to/script.js ... would this be okay?
Jenko
+2  A: 

There is a difference between an attribute value delimiter and a quote or double quote character.

You have to use a literal " or ' to delimit attribute values (except where delimiters are optional). In this case, the squence of bytes means "attribute value delimited" not "(double) quote mark"

The character references can be used to represent a (double) quote mark but is a more complicated and inefficient way compared to using a literal so should only be used when the literal is not available (i.e. when it would be an attribute value delimiter because you are inside an an attribute value where the opening delimiter was that character).

David Dorward