0

I am trying to insert a tag into the page. but inside that a tag, it has both single quote and double quote, so i try put that part into an variable Var content. Can someone tell me why this var content is not showing on onclick after code runs?

var content = "javascript:window.open('https://ds.contactatonce.com/ds/p10819departmentselector.htm?OriginationUrl='+encodeURIComponent(location.href),'','resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=no,status=no,height=520,width=450');return false;" $('<a style ="float: left; margin-top: 20px" href="#" onclick=" + content + " ><img onerror="this.height=0;this.width=0;" border="0" alt="Click to instant message Representative Now!" title="" src="https://dm5.contactatonce.com/getagentstatusimage.aspx?MerchantId=270075&ProviderId=10819&PlacementId=10"></a>').insertBefore('.header-contact-phone'); 

it was like this before but it keep showing errors

$('<a style ="float: left; margin-top: 20px" href="#" onclick="javascript:window.open('https://ds.contactatonce.com/ds/p10819departmentselector.htm?OriginationUrl='+encodeURIComponent(location.href),'','resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=no,status=no,height=520,width=450');return false;" ><img onerror="this.height=0;this.width=0;" border="0" alt="Click to instant message !" title="Click to instant message a Now!" src="https://dm5.contactatonce.com/getagentstatusimage.aspx?MerchantId=270075&ProviderId=10819&PlacementId=10"></a>').insertBefore('.header-contact-phone'); 
6
  • var content = "javascript:window.open('ds.contactatonce.com/ds/… false;" $('').insertBefore('.header-contact-phone'); Commented May 20, 2017 at 17:53
  • Please move all code into the question itself, rather than adding it as a comment. Commented May 20, 2017 at 17:56
  • I did that before, but is causing a error because inside the double quotes it has single quote, Commented May 20, 2017 at 17:59
  • $('<a style ="float: left; margin-top: 20px" href="#" onclick="javascript:window.open('ds.contactatonce.com/ds/… false;" ><img onerror="this.height=0;this.width=0;" border="0" alt="Click to instant message !" title="Click to instant message a Now!" src="dm5.contactatonce.com/…; Commented May 20, 2017 at 17:59
  • ^ --- this doesn't help. Please edit the question... Commented May 20, 2017 at 18:00

1 Answer 1

2

Use the escape character \ before the quotes like this:

var y = "We are the so-called \"Vikings\" from the north.";

see this links:

https://www.w3schools.com/js/js_strings.asp

https://www.w3schools.com/js/tryit.asp?filename=tryjs_strings_escape

Sign up to request clarification or add additional context in comments.

1 Comment

Among all the beautiful documentation online it's so sad to see such low quality links here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.