Click to See Complete Forum and Search --> : in url, we use & or &?


blackhorse
05-15-2007, 05:27 PM
OK, so the rules are in the php scripts we use & in the url values. in the html, we use the &.

How about javascript, we use the & in the url values in the javasript too, like in the php script, right?

But how about the html codes like this

<a href="javascript: if (confirm('go to next page?')) location.href='test2.php?id=1&amp;list=1';">test2.php by loclation &amp;amp;</a>

In the above case, should I use &amp; as in html or should I use & as in script? It seems that we should use &amp; as in html. Because the javascript codes are not in the <script></script? blocks?

Thanks!

Weedpacket
05-15-2007, 05:32 PM
Nothing to do with Javascript, everything to do with the fact that it's HTML. In HTML, all & characters should be encoded as &amp;, including those inside attribute values.

HTML 4.0.1 Specification (http://www.w3.org/TR/html401/charset.html#h-5.3.2)
Authors should use "&amp;" (ASCII decimal 38) instead of "&" to avoid confusion with the beginning of a character reference (entity reference open delimiter). Authors should also use "&amp;" in attribute values since character references are allowed within CDATA attribute values.

blackhorse
05-15-2007, 06:34 PM
tested in both IE and firefox. If it is in the javascript blocks, then it has to be & instead of &amp;

When calling the javascript function and pass the parameter in html, it should be &amp; in the parameter passed to javascript funcition.

Weedpacket
05-16-2007, 06:08 AM
tested in both IE and firefox. If it is in the javascript blocks, then it has to be & instead of &amp;Yes, because the contents of <script> blocks are interpreted as CDATA.

http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1[/quote]
<!ELEMENT SCRIPT - - %Script; -- script statements -->

[url]http://www.w3.org/TR/html401/sgml/dtd.html#Script
<!ENTITY % Script "CDATA" -- script expression -->
http://www.w3.org/TR/html401/types.html#type-cdata
Although the STYLE and SCRIPT elements use CDATA for their data model, for these elements, CDATA must be handled differently by user agents. Markup and entities must be treated as raw text and passed to the application as is. The first occurrence of the character sequence "</" (end-tag open delimiter) is treated as terminating the end of the element's content. In valid documents, this would be the end tag for the element.

Note that XHTML is a bit more consistent about this, because XML introduced <![CDATA[ ... ]]>