Unable to escape characters. What now?

  • Thread starter Diarmaid McGleenan
  • Start date
D

Diarmaid McGleenan

I have a javascript function called ShowActiveLink to which I pass a
full <a href="blah.htm"
onClick="javascript:newWindow('quotedStuff');"> link. (See below.)

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

<a href="javascript:newWindow('http://www.vre.org/vremap/app?action=ovmap');"
target="_blank">VRE Service Status</a></li>
---------------

My problem is that I have no method of escaping the single quotes in
newWindow('') because the entire <a href> is placed there dynamically
by our content management system when the file is generated.

I've thought of

void ShowActiveLink(escape('<a href="javascript:newWindow('...')'));

but it doesn't work because of the single quotes contained within the
<a href>. I thought of using VBScript, but that doesn't work either
since the double quotes in the link cause the string to close too
early and the compiler blows up.

Keeping in mind that I can't manually escape the href, what can I do
now?
 
M

McKirahan

Diarmaid McGleenan said:
I have a javascript function called ShowActiveLink to which I pass a
full <a href="blah.htm"
onClick="javascript:newWindow('quotedStuff');"> link. (See below.)

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

<a href="javascript:newWindow('http://www.vre.org/vremap/app?action=ovmap');"
target="_blank">VRE Service Status</a></li>
---------------

My problem is that I have no method of escaping the single quotes in
newWindow('') because the entire <a href> is placed there dynamically
by our content management system when the file is generated.

I've thought of

void ShowActiveLink(escape('<a href="javascript:newWindow('...')'));

but it doesn't work because of the single quotes contained within the
<a href>. I thought of using VBScript, but that doesn't work either
since the double quotes in the link cause the string to close too
early and the compiler blows up.

Keeping in mind that I can't manually escape the href, what can I do
now?

Try using the backquote ( ` ) character instead; I think this works...
 
M

Michael Winter

[snip]
<script language="javascript">

Not related to a solution, but the language attribute has been deprecated
for over six years. Use the (required) type attribute instead:

<script type="text/javascript">

[snip]

Three points:

1) What is the purpose of the "void"?
2) See <URL:http://jibbering.com/faq/#FAQ4_24>.
3) The escape function escapes the contents of a string. That string still
has to be valid.

[snip]

You have no choice. You *have* to escape the innermost quotes with a
backslash.
Try using the backquote ( ` ) character instead; I think this works...

No, it doesn't.

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
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top