XHTML Compatibility - Storing HTML in a Javascript variable
I am stumped here. I am working on switching my doctype to XHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Since doing so, I've run into a validation issue. I'm using Dynamic Drive's Ultimate Fade-in slideshow (found here: http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm) and feeding in all of my variables from a database. To make that work, I have to populate some javascript variables.
After I use the database to write out my javascript, I end up with the following:
<script type='text/javascript'>
var img1, img2, im3, img4, lnk1, lnk2, lnk3, lnk4, txt1, txt2, txt3, txt4;
img1 = "image1.jpg";
lnk1 = "/link1.php";
txt1 = "<font style='font-size: 14px;'><a href='/link1.php'>Article 1</a></font><br />Article 1 Content...";
img2 = "image2.jpg";
lnk2 = "/link2.php";
txt2 = "<font style='font-size: 14px;'><a href='/link2.php'>Article 2</a></font><br />Article 2 Content...";
img3 = "image3.jpg";
lnk3 = "/link3.php";
txt3 = "<font style='font-size: 14px;'><a href='/link3.php'>Article 3</a></font><br />Article 3 Content...";
img4 = "image4.jpg";
lnk4 = "/link4.php";
txt4 = "<font style='font-size: 14px;'><a href='/link4.php'>Article 4</a></font><br />Article 4 Content...";
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
dimensions: [600, 400], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [
[img1, lnk1, "", txt1],
[img2, lnk2, "", txt2],
[img3, lnk3, "", txt3],
[img4, lnk4, "", txt4] // no trailing comma after very last image element!
],
displaymode: {type:'auto', pause:5000, cycles:0, wraparound:false},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 500, //transition duration (milliseconds)
descreveal: "always",
togglerid: ""
})
</script>
I get a number of validation errors all pointing to the html code I am storing in t开发者_运维技巧he txt[x] variables.
Samples: Line 239, Column 39: document type does not allow element "font" here
txt1 = "<font style='font-size: 14px;'><a href='/link1.php…
Line 239, Column 126: document type does not allow element "br" here
…Article 1</a></font><br />Article 1 Content …
Am I missing something obvious? Or is HTML text in a javascript variable not an option when it comes to being XHTML compliant?
What validator are you using?
The w3c validator does not ignore what's inside the script tags, so if you have HTML in your script the validator will try to validate it as XHTML.
Put your script into a separate file.
Also, why are you worrying about validation if you are going to insert HTML4 tags via script?
font
is deprecated in HTML 4 Strict and XHTML. Use the proper semantic element and style it, which would be a
in this case.
精彩评论