Results 1 to 3 of 3

Thread: Opeining link for random pictures in new window...

  1. #1
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Opeining link for random pictures in new window...

    I tried to read as many posts as I could find on this topic but did not see any that answered the question I was looking for. Bottom line is that I use the random picture generator below and it works great. It allows you to link the pictues to specific websites which is exactly what I wanted to do. However, I'm having a very difficult time trying to find a way to open these links in a new window when the pictures are clicked on. Can anyone help?

    Thanks in advance...

    Code:
    <SCRIPT LANGUAGE="Javascript">
    function banner() { } ; b = new banner() ; n = 0
    b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner2.jpg' border='0' ALT='Haunted House'></A>"
    b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner3.jpg' border='0' ALT='Graves in the Snow'></A>"
    b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner4.jpg' border='0' ALT='Insane Joker'></A>"
    b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner5.jpg' border='0' ALT='Fangs'></A>"
    b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner6.jpg' border='0' ALT='Screaming Clowns'></A>"
    b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner7.jpg' border='0' ALT='Dead Servant'></A>"
    i=Math.floor(Math.random() * n) ;
    document.write( b[i] )
    </SCRIPT>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you only want certain ones to open in a new window/tab, you can add the attribute target='_blank' to the a tag for those, ex:

    Code:
    b[n++]= "<A HREF='index.html' target='_blank'><IMG name=randimg SRC='images/interface/banner2.jpg' border='0' ALT='Haunted House'></A>"
    If you want all of them to open in a new window/tab, you can add that to all of them. Or you can leave them as is and change:

    Code:
    document.write( b[i] )
    to:

    Code:
    document.write( b[i].split("A H").join("A target='_blank' H") )
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the quick response. The code is Perfect.

    Thanks!!!

Similar Threads

  1. Replies: 6
    Last Post: 12-23-2008, 08:05 PM
  2. Link a item inside of a pictures
    By Frontpage_user in forum Looking for such a script or service
    Replies: 4
    Last Post: 02-16-2007, 03:23 AM
  3. Random Link script anywhere?
    By bsheets in forum Dynamic Drive scripts help
    Replies: 6
    Last Post: 03-28-2006, 03:03 PM
  4. Replies: 1
    Last Post: 10-22-2005, 09:50 PM
  5. Pictures in Link Description??
    By Litis Angelus in forum HTML
    Replies: 2
    Last Post: 04-15-2005, 11:18 PM

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
  •