Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Single and double quote problems. (http://www.velocityreviews.com/forums/t880525-single-and-double-quote-problems.html)

Diarmaid McGleenan 11-10-2004 02:37 PM

Single and double quote problems.
 
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.

Michael Winter 11-10-2004 02:51 PM

Re: Single and double quote problems.
 
On 10 Nov 2004 06:37:45 -0800, Diarmaid McGleenan
<calvertwebteam@yahoo.com> wrote:

> 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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Diarmaid McGleenan 11-11-2004 06:24 PM

Re: Single and double quote problems.
 
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



All times are GMT. The time now is 02:04 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.