Very simple javascript popup link question

Discussion in 'JavaScript' started by jpmad4it, Jan 17, 2008.

  1. #1
    Hi there,

    I am trying to edit the following JS below. This is a javascript file itself and not an HTML file, so the syntax is confusing me. I am struggling to get the correct syntax for adding the link on the image in the array. All its meant to do is simply pop-up a window using a link on an image in the array.

    The problem line out of the whole code is this one:

    leftrightslide[0]='<a href="javascript:PHOTO_WINDOW('Flash/scroll_images/orig/image0.jpg','1000','1000');"><img src="Flash/scroll_images/image0.jpg" alt="" /></a>';
    Code (markup):
    Here is the full part of this code:

    
    function PHOTO_WINDOW(link, width, height) //URL, height and width of image passed to function
    {
       var photoWindow = window.open(link,"photo",'toolbar=0, title=0, location=0, status=0, directories=0,status_bar=0,menubar=0,scrollbars=1,resizable=1');
    }
    
    //Specify the slider's images
    var leftrightslide=new Array();
    var finalslide=''
    leftrightslide[0]='<a href="javascript:PHOTO_WINDOW('Flash/scroll_images/orig/image0.jpg','1000','1000');"><img src="Flash/scroll_images/image0.jpg" alt="" /></a>';
    leftrightslide[1]='<img src="Flash/scroll_images/image1.jpg" alt="" />'
    leftrightslide[2]='<img src="Flash/scroll_images/image2.jpg" alt="" />'
    leftrightslide[3]='<img src="Flash/scroll_images/image3.jpg" alt="" />'
    leftrightslide[4]='<img src="Flash/scroll_images/image4.jpg" alt="" />'
    leftrightslide[5]='<img src="Flash/scroll_images/image5.jpg" alt="" />'
    leftrightslide[6]='<img src="Flash/scroll_images/image6.jpg" alt="" />'
    leftrightslide[7]='<img src="Flash/scroll_images/image7.jpg" alt="" />'
    leftrightslide[8]='<img src="Flash/scroll_images/image8.jpg" alt="" />'
    leftrightslide[9]='<img src="Flash/scroll_images/image10.jpg" alt="" />'
    leftrightslide[10]='<img src="Flash/scroll_images/image11.jpg" alt="" />'
    leftrightslide[11]='<img src="Flash/scroll_images/image12.jpg" alt="" />'
    leftrightslide[12]='<img src="Flash/scroll_images/image13.jpg" alt="" />'
    leftrightslide[13]='<img src="Flash/scroll_images/image14.jpg" alt="" />'
    leftrightslide[14]='<img src="Flash/scroll_images/image15.jpg" alt="" />'
    leftrightslide[15]='<img src="Flash/scroll_images/image16.jpg" alt="" />'
    leftrightslide[16]='<img src="Flash/scroll_images/image17.jpg" alt="" />'
    leftrightslide[17]='<img src="Flash/scroll_images/image18.jpg" alt="" />'
    
    Code (markup):
    If anyone can help then you'll be a legend to me!

    Kind regards
    Jonathan
     
    jpmad4it, Jan 17, 2008 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try it this way:
    
    leftrightslide[0]="<a href='#' onclick=\"PHOTO_WINDOW('Flash/scroll_images/orig/image0.jpg','1000','1000');return false;\"><img src='Flash/scroll_images/image0.jpg' alt='' /></a>";
    Code (markup):
     
    Mike H., Jan 17, 2008 IP
  3. jpmad4it

    jpmad4it Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    bloody legend it works ;)

    Thank you sooooo much!

    I knew it was simple!
     
    jpmad4it, Jan 17, 2008 IP
  4. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're welcome. The general rule is to use single quotes inside double quotes, when double quotes are required, when calling a function that passes arguments within single quotes, then "escape" the double quotes, with a leading backslash:

    onclick=\"PHOTO_WINDOW('Flash/scroll_images/orig/image0.jpg','1000','1000');return false;\">
     
    Mike H., Jan 17, 2008 IP
  5. jpmad4it

    jpmad4it Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ah yeah, I remember using that kind of syntax in PHP when placing HTML code in the file.
     
    jpmad4it, Jan 17, 2008 IP