Jump to content

Escaping Quotes (php+js)


Adeus

Recommended Posts

Hello,

 

I am working with the following code.

echo "
<a href=\"javascript:void(0);\" onclick=\"return coolTip('<div id=\'ctInside\'><a href=\'JavaScript:goVisitSite(\'image.jpg\')\'><span class=\'lad\'>CLICK</span></a></div>', WIDTH, 430, HEIGHT, 230); return true;\" onmouseout=\"nd(); return true;\">IMAGE</a>
";

 

Whenever I mouse over the link it generates, it only reads javascript:goVisitSite(. I've tried escaping it more than once, I've tried using double quotes, I've tried everything I could think of. Any suggestions are much appreciated!

Link to comment
Share on other sites

I tried changing the quotes to their respective entities as you suggested, Little Guy. Unfortunately, it did not work. Is there something I can do to my JavaScript in the head?

 

<script type="text/javascript" language="JavaScript">
function goVisitSite(Site)
{
NewWindow1 = window.open(Site,
	"viewwin",
	"toolbar=0,width=350,height=450,resizable=no,screenX=400,screenY=300");
}
</script>

 

 

Link to comment
Share on other sites

within cool tip, change

 

" to "

and

' to '

That has nothing to do with JS.

 

Pick a set of quotes (single or doubles) and stick with it... keep escaping (you'll need to double-escape).

 

Better yet, make some variables!

Link to comment
Share on other sites

I think you might be missing a closing double quote from the onclick attribute. Can you post the output HTML here (i.e. from View Source in your browser)?

 

I find that the easiest way to do quotes is to first decide what the JS code should be when in the HTML page, like this (abridged):

<a href="javascript:void(0);" onclick="return coolTip('<div id=\'ctInside\'>...</div>')\'">link</a>

(You'll need to do that "doubly" for the HTML inside the JS...)

 

Then if you are going to echo that in your PHP code, if you are using double quotes, simply escape all double quotes in your HTML. If you have double quotes already escaped for javascript purposes you'll need to change them from \" to \\\"

 

What you really ought to be doing though is not using HTML in a JS function call. Pass variables like the id and generate the HTML in the coolTip function.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.