Unable to escape characters. What now?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Diarmaid McGleenan

    #1

    Unable to escape characters. What now?

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

    ---------------
    <script language="javas cript">void ShowActiveLink( '<a
    href="javascrip t:newWindow('ht tp://www.vre.org/');"
    target="_blank" >VRE Service Status</a>');</script>

    <a href="javascrip t:newWindow('ht tp://www.vre.org/vremap/app?action=ovma p');"
    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="javascrip t: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?
  • McKirahan

    #2
    Re: Unable to escape characters. What now?

    "Diarmaid McGleenan" <calvertwebteam @yahoo.com> wrote in message
    news:94b23ce5.0 411090913.1525f 84c@posting.goo gle.com...[color=blue]
    > I have a javascript function called ShowActiveLink to which I pass a
    > full <a href="blah.htm"
    > onClick="javasc ript:newWindow( 'quotedStuff'); "> link. (See below.)
    >
    > ---------------
    > <script language="javas cript">void ShowActiveLink( '<a
    > href="javascrip t:newWindow('ht tp://www.vre.org/');"
    > target="_blank" >VRE Service Status</a>');</script>
    >
    > <a[/color]
    href="javascrip t:newWindow('ht tp://www.vre.org/vremap/app?action=ovma p');"[color=blue]
    > 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="javascrip t: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?[/color]

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


    Comment

    • Michael Winter

      #3
      Re: Unable to escape characters. What now?

      On Tue, 09 Nov 2004 18:05:36 GMT, McKirahan <News@McKirahan .com> wrote:
      [color=blue]
      > "Diarmaid McGleenan" <calvertwebteam @yahoo.com> wrote in message
      > news:94b23ce5.0 411090913.1525f 84c@posting.goo gle.com...[/color]

      [snip]
      [color=blue][color=green]
      >> <script language="javas cript">[/color][/color]

      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]
      [color=blue][color=green]
      >> void ShowActiveLink( escape('<a href="javascrip t:newWindow('.. .')'));[/color][/color]

      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]
      [color=blue][color=green]
      >> Keeping in mind that I can't manually escape the href, what can I do
      >> now?[/color][/color]

      You have no choice. You *have* to escape the innermost quotes with a
      backslash.
      [color=blue]
      > Try using the backquote ( ` ) character instead; I think this works...[/color]

      No, it doesn't.

      Mike

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

      Comment

      Working...