I have an embedded map on a page. It won't W3C validate due to unencoded ampersands in the url for a marker. If I encode the &
as &
then it validates but the marker doesn't show up. Is there a solution for this dilemma? I've seen other people that also have this problem, but I not seen any solutions.
Asked
Active
Viewed 652 times
0

geocodezip
- 158,664
- 13
- 220
- 245

Steve Taylor
- 1
- 1
-
possible duplicate of [Do I encode ampersands in ?](http://stackoverflow.com/questions/3705591/do-i-encode-ampersands-in-a-href) – Max Truxa Dec 21 '13 at 22:25
-
can you give an example-URL? – Dr.Molle Dec 21 '13 at 22:33
-
Here is the page: http://calpropertyappraisals.com/contact.php – Steve Taylor Dec 21 '13 at 23:08
-
I know I should encode the &, but when I do, it breaks the google maps marker function. it contains this url: icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=S|FF0000|000000' }); – Steve Taylor Dec 21 '13 at 23:11
-
[chart.apis.google.com/chart?chst=d_map_pin_letter&chld=S|FF0000|000000](http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=S|FF0000|000000) – Max Truxa Dec 22 '13 at 00:10
-
The most obvious (and cleanest) approach would be to move the JavaScript to another file. – Max Truxa Dec 22 '13 at 00:45
-
OK, if I wrap the script with the CDATA tags as recommended below, all is well. I'll also try moving the js to a separate file. Thanks – Steve Taylor Dec 22 '13 at 03:43
-
1I have now separated the js code into its own file and now the map marker works and the page passes the validation. Thanks. – Steve Taylor Dec 22 '13 at 16:47
1 Answers
0
The problem is the W3C validator attempting to validate javascript as HTML
Wrap your script in
<script type="text/javascript">
//<![CDATA[
//]]>
</script>

geocodezip
- 158,664
- 13
- 220
- 245
-
-
It's no problem of the validator. The document is declared as XHTML, and in XHTML the [content of script-element is defined as #PCDATA](http://www.w3.org/TR/xhtml1/#h-4.8) (parsed character data) . It's simply not valid, and the validator is doing what he has been intended for. – Dr.Molle Dec 22 '13 at 02:35