Escaping style and script data

323 views

Published on

Escaping style and script data in old browsers didn't support them and dealing with the xhtml besides html.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
323
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Escaping style and script data

  1. 1. Escaping Style And Script Data<br />Mohamed Fadel Buffon<br />
  2. 2. Hiding from unsupporting browsers<br />Make them believe that the data is inside a comment.<br />For example :<br /><style type="text/css"><br /> <!--<br /> body<br /> {<br /> background: #eee;<br /> color: #000;<br /> }<br /> --><br /></style><br />
  3. 3. Hiding from unsupporting browsers (Con’t) <br />With the script element, use a single line ECMAScript comment (//) to hide the end token from browsers .<br />For example :<br /><script type="text/javascript"><br /> <!--<br /> function foo ()<br /> {<br /> bar();<br /> }<br /> //--><br /></script><br />
  4. 4. In HTML, their contents are defined as CDATA, meaning everything from the start of the contents to the next occurrence of the closing token (</ in this case) is considered character data that isn't parsed as markup.<br />Parsing differences between HTML and XHTML<br />
  5. 5. in XHTML their contents are defined as PCDATA, meaning the contents are parsed as markup.<br />If you wish to include <and& characters in your script or style sheet, you will run into problems.<br />Parsing differences between HTML and XHTML (Con’t)<br />
  6. 6. in XHTML, you must mark up a special CDATAsection.<br />So, use the styling or scripting language to comment out the CDATA section markers.<br />Parsing differences between HTML and XHTML (Con’t)<br />
  7. 7. For example:<br />Parsing differences between HTML and XHTML (Con’t)<br /><style type="text/css"><br /> /*<![CDATA[*/<br /> body<br /> {<br /> background: #eee;<br /> }<br /> /*]]>*/<br /></style><br /> <br /><script type="text/javascript"><br /> //<![CDATA[<br />document.title = "Foo & Bar";<br /> //]]><br /></script><br />
  8. 8. to write XHTML that can also be handled by common HTML user agents as well as old browsers that don't support the styleand scriptelements.<br />Putting the two together<br /><style type="text/css"><br /> <!--/*--><![CDATA[/*><!--*/<br /> body<br /> {<br /> background: #eee;<br /> }<br /> /*]]>*/--><br /></style><br /> <br /><script type="text/javascript"><br /> <!--//--><![CDATA[//><!--<br />document.title = "Foo & Bar";<br /> //--><!]]><br /></script><br />
  9. 9. Thank You<br />Contact : walk2remember2010@gmail.com<br />

×