SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    escape quote character

    I have try almost everything and I have no idea what would be the correct sytax for the following line:

    HTML Code:
    <a style="margin:10px;" href="javascript:void(0);" onclick="javascript: jQuery.facebox('<img src=\"/image.php/imagename.png?width=130&height=130&cropratio=1:1&image=/userimages/company_images/imagename.png\"/>');">
    Please could you help me with this problem.

    tnx

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Location
    Kingdom of Saudi Arabia
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try below...
    Code:
    somewhere in head...
    <script src="jquery.js" type="text/javascript"></script>
    <link href="/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
    <script src="/facebox/facebox.js" type="text/javascript"></script>
    <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function($) {
      		$('a[rel*=facebox]').facebox()
    	}) 
        //]]>
    </script>
    
    somewhere in body...
    <a style="margin:10px;" href="#" rel="facebox"><img src="/image.php/imagename.png?width=130&height=130&cropratio=1:1&image=/userimages/company_images/imagename.png" /></a>

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code HTML4Strict:
    <a style="margin:10px" href="#" onclick="jQuery.facebox('<img src=&quot;/image.php/imagename.png?width=130&amp;height=130&amp;cropratio=1:1&amp;image=/userimages/company_images/imagename.png&quot;/>'); return false;">
    1. Use &quot; to escape a double quotation mark in HTML.
    2. You must escape '&' characters as &amp;.
    3. Don't use the javascript: pseudo-scheme in the href; return false from the event handler instead.
    4. Don't prefix javascript: in the onclick attribute! It's not a URI, and you're just putting a completely useless label in there!
    Birnam wood is come to Dunsinane

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Instead of adding JavaScript to the head, put the JavaScript at the bottom of the body and then you can run it straight away knowing that the DOM elements it is referenceing already exist.

    If using an <a> tag then the href must point to the web page that you want your visitors without JavaScript to get to if they click on the link. If you don't want those visitors to have anything happen when they click the image then replace the <a> with a <span> so that there is no default action.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tnx to everybody, I tried AutisticCuckoo solution and it works!


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
  •