0

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>

4 Answers 4

1

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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>

Comments

1
<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>

Comments

1
<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.