Need help modifying javascript snippet
Google optimizer includes the following snippet as part of their conversion code. Unfortunately, the CMS we're using automatically converts the single quotes to ASCII (& #39;). I'm a novice with JS, but my understanding is that single quotes and double quotes are basically interchangeable. However, it's not a straight swap as there are existing double quotes in the script. Is it possible to replace the single quotes with doubles in this script? If so, how do I escape the existing double quotes in the URL portion to keep the script functioning?
<script type="text/javascript">
if(typeof(_gat)!开发者_运维知识库='object')document.write('<sc'+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc'+'ript>')</script>
Yes, single and double quotes are interchangeable, you just need to escape the currently double quotes inside of the strings with \"
, and replace all the single quotes for double quotes:
<script type="text/javascript">
if(typeof(_gat)!="object")document.write("<sc"+"ript src=\"http"+
(document.location.protocol=="https:"?"s://ssl":"://www")+
".google-analytics.com/ga.js\"></sc"+"ript>");
</script>
Try this:
<script type="text/javascript">
if(typeof(_gat)!="object")document.write("<sc"+"ript src=\"http"+
(document.location.protocol=="https:"?"s://ssl":"://www")+
".google-analytics.com/ga.js\"></sc"+"ript>")</script>
<script type="text/javascript">if(typeof(_gat)!="object")
document.write("<sc"+"ript src=\"http"+
(document.location.protocol=="https:"?"s://ssl":"://www")+
".google-analytics.com/ga.js\"></sc"+"ript>")</script>
<script type="text/javascript">
if(typeof(_gat)!="object")document.write("<sc"+"ript src=http"+
(document.location.protocol=="https:"?"s://ssl":"://www")+
".google-analytics.com/ga.js></sc"+"ript>")</script>
精彩评论