views:

49

answers:

4

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>
+1  A: 

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>
CMS
+1  A: 

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>
Diodeus
+1  A: 
<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>
Victor
+1  A: 
<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>
RayZ