Single and double quote problems.

D

Diarmaid McGleenan

Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...

I have a js function called ShowActiveLink which accepts a string
containing the full "<a href...>" element. My problem is that some of
the hrefs contain both single and double quotes and I don't have the
ability to escape these characters manually because our content
management system inserts the href when it generates the site.
Therefore I end up with code like this:

<script language="javascript">
void ShowActiveLink('<a
href="javascript:newWindow('http://www.vre.org/');">VRE Service
Status</a>');
</script>
<a href="javascript:newWindow('http://www.vre.org/');">VRE Service
Status</a></li>

....which causes a compiler error.

(Incidentally, the function searches for the current page name inside
the provided href string. If it's found it displays a <li
style="list-style-image: url('images/arrow-right.gif');"> before the
link. Otherwise, it displays an <li> without a bullet.)

Do any of you know a function or something that I can wrap around this
href to escape the string, regardless of how many single or
double-quotes there are, before it is passed to the function?

Thanks,
--Diarmaid.
 
M

Michael Winter

Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...

Actually, I think it is, but in any case it is the same question you
posted yesterday. I won't repeat everything I wrote then so if you haven't
done so already, please read my previous post.

[snip]
Do any of you know a function or something that I can wrap around this
href to escape the string, regardless of how many single or
double-quotes there are, before it is passed to the function?

This is a *syntax* error. No amount of function calls can correct that,
only modification of the script itself. You will either have to instruct
your content management system (which I believe you blamed yesterday) to
output \" or \' when writing the string literal, or modify the output
afterwards.

Syntax has to be correct *before* it gets to the client. You can't correct
it afterwards.

Mike
 
D

Diarmaid McGleenan

Thanks for your suggestion Michael, and sorry about the double post
for the same problem. I thought the other message didn't make it to
the ng for whatever reason.

--Diarmaid.
Hi all. This isn't quite the same single/double-quote problem we see
posted a multitude of times in this ng. Read on...

Actually, I think it is, but in any case it is the same question you
posted yesterday. I won't repeat everything I wrote then so if you haven't
done so already, please read my previous post.

[snip]
Do any of you know a function or something that I can wrap around this
href to escape the string, regardless of how many single or
double-quotes there are, before it is passed to the function?

This is a *syntax* error. No amount of function calls can correct that,
only modification of the script itself. You will either have to instruct
your content management system (which I believe you blamed yesterday) to
output \" or \' when writing the string literal, or modify the output
afterwards.

Syntax has to be correct *before* it gets to the client. You can't correct
it afterwards.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top