0

I am creating a list of links in javascript but it appears that the browser are translating some caracters

This is my code

vLinea += "<a href='#' onclick='window.open('frmEnviarPorCorreo.aspx?Pr_Id=" + pData.Pr_Id + "'"
vLinea += ", '_blank', 'location=yes,height=570,width=520,scrollbars=no,status=no');>"
vLinea += "<img   class='imgShare'  src='images/icoEmail.png'>" 
vLinea += "</a> </li>"

What I would like is this

<a href="#" onclick="window.open('frmenviarporcorreo.aspx?pr_id=12806','_blank','location=yes,height=570,width=520,scrollbars=no,status=no');"><img class="imgShare" src="images/icoEmail.png"></a>

What I am getting is this, Some ' are translated as " some " are added I don't know why

<a href="#" onclick="window.open(" frmenviarporcorreo.aspx?pr_id="12806'," '_blank',="" 'location="yes,height=570,width=520,scrollbars=no,status=no');"><img class="imgShare" src="images/icoEmail.png"></a>
Marc B
  • 356,200
  • 43
  • 426
  • 500
Corobori
  • 303
  • 3
  • 13

2 Answers2

0

You need escape character() if you want to add a quote mark in the middle of the same kind of quotes without terminating the string. I think the only escape you need is on the first row just after "window.open, to not terminate the onclick quote just before you want to give it the path.

vLinea += "<a href='#' onclick='window.open(\'frmEnviarPorCorreo.aspx?Pr_Id=" + pData.Pr_Id + "'"
vLinea += ", '_blank', 'location=yes,height=570,width=520,scrollbars=no,status=no');>"
vLinea += "<img   class='imgShare'  src='images/icoEmail.png'>" 
vLinea += "</a> </li>"
Mikael Puusaari
  • 854
  • 1
  • 10
  • 14
0

Try using the escape for your quotes:

vLinea += "<a href=\"#\" onclick=\"window.open(\'frmenviarporcorreo.aspx?pr_id=\'" + pData.Pr_Id +"\'"
vLinea += "\',\'_blank\',\'location=yes,height=570,width=520,scrollbars=no,status=no\');\">"
vLinea += "<img class=\"imgShare\" src=\"images/icoEmail.png\">"
vLinea += "</a> </li>"

The escape works for single or double quotes.

Matt Jackson
  • 158
  • 9