css - How can I place HTML in a JavaScript string and have it validate? -


i want show different css files depending on browser user using. want on js , on client side. using code this.

 <script language="javascript" type="text/javascript">  if ((navigator.useragent.indexof("msie")) >= "0"){     document.write("<link rel=\"stylesheet\" href=\"css/common.ie.css\" type=\"text/css\"   }  if ((navigator.useragent.indexof("chrom")) >= "0"){     document.write("<link rel=\"stylesheet\" href=\"css/common.chrome.css\" type=\"text/css\" />");  } 

*the problem code not valid. how can solve problem. if check document w3 checker. show now: line 22, column 90: document type not allow element "link" here*****

…nt.write("<link rel='stylesheet' href='css/common.ie.css' type='text/css' />"); 

line 25, column 35: attribute value must literal unless contains name characters

document.write("<link rel=\"stylesheet\" href=\"css/common.chrome.css\"… 

break in sub-strings not detected ..

document.write("<l" + "ink ... 

or add comments this

<script type="text/javascript"> //<!--  if ((navigator.useragent.indexof("msie")) >= "0"){     document.write("<link rel=\"stylesheet\" href=\"css/common.ie.css\" type=\"text/css\"   }  if ((navigator.useragent.indexof("chrom")) >= "0"){     document.write("<link rel=\"stylesheet\" href=\"css/common.chrome.css\" type=\"text/css\" />");  }   //--> </script> 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -