SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: Double Escape

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Double Escape

    I am having trouble with some code on my site. I have an arcade with game links that have tooltips which display thumbnails. The tooltip code for each link is in the title attribute. I am using javascript to write the code for these links with tooltips so that if javascript is disabled the title attribute displays something different. My problem is some of the tooltip thumbnails contain an apostrophe (') in their src code. I use a backslash (\) to escape this once but I need to escape it again. Is this possible. The reason I need to escape it twice is one to escape it from the javascript and another to escape it from the src tag (src='Thumbs/image'src.jpg'). Any help would be greatly appreciated, sorry if I confuse any of you.

    Thanks,
    High Caliber

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try \u0027 ?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what do u mean? Can you help me understand what you are talking about.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it's almost impossible to decipher your post. Did you use an Enigma machine to write it?

    You can do this:

    src="Thumbs/image'src.jpg"

    If that doesn't help, post a short, simple script that demonstrates your problem.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am writing this in PHP and Javascript and here is what it outputs...
    Code:
    <script>
    document.write('<a href="game.php?id=17" title="header=[Stuart\'s Xtreme Skateboarding] body=[<div style=\'float: left;\'><img alt=\'\' src = \'Thumb/stuart\'s_xtreme_skateboarding.jpg\' style=\'border: 1px solid black; height: 50px; width: 50px;\' /></div><div style=\'float: right; vertical-align: bottom; width: 100px;\'><b>Rating: </b>Not rated<br/><b>Description: </b>Try your hand at this fun skateboarding flash game...</div><div style=\'clear: both;\'></div>] cssheader=[tooltip_header] cssbody=[tooltip_body]">');
    document.write('Stuart\'s Xtreme Skateboar...');
    document.write('</a>');
    </script>
    <noscript>
    <a href="game.php?id=17" title="Stuart's Xtreme Skateboarding - Try your hand at this fun skateboarding flash game...">Stuart\'s Xtreme Skateboar...</a>
    </noscript>
    I can't do it like you suggested becuase I can not use double quotes in the title attribute of a link.
    The code in the title attribute is for my tooltip which works by loading a javascript file.

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not simple enough. Change the href to "#", delete all the attributes and styles that aren't necessary to demonstrate your problem, remove the <noscript> tags(which should never be used anyway) and then use the minimum amount of text necessary in the title attribute e.g. one word. Also, post the output that you get, and what output you want.

    The idea is to make it simple for someone to help you, not make them decipher a bunch of stuff that has no bearing on the problem.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a simplified version so you can see where my issue is...
    Code:
    <script>
    document.write('<a href="#" title="<img src =\'stuart\'s_xtreme_skateboarding.jpg\' />">Game Title</a>');
    </script>

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, post the output that you get, and what output you want.
    ....

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, don't use an <img> tag in the title attribute. No one that tests your script is going to have that img. Just put some text in there that is as short as possible to demonstrate your problem.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need the image because that is what is causing my error. The image tag attributes use ' and there is a ' in the image src.

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need the image because that is what is causing my error. The image tag attributes use ' and there is a ' in the image src.
    You can't duplicate that using a string of random characters?

    Goodbye. I'm through pulling teeth. I've posted this twice:
    Also, post the output that you get, and what output you want.
    but apparently you think that is optional.

    Good luck to you.

  12. #12
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stuart's = Stuart\u0027s


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •