www.webdeveloper.com
Results 1 to 4 of 4

Thread: Random Image with onclick popup link

  1. #1
    Join Date
    Mar 2003
    Posts
    2

    Random Image with onclick popup link

    Hi
    I'm setting up a random script to select from 5 different images, and they each have their own url they will link to when clicked. This works fine. The problem I'm having is when clicking on these random images when they load, having the url they link to be in a popup sized window. I know about onclick events, etc, but tieing all these things together is what's screwing me up. Any help would be appreciated. Thanks.
    Here's my code so far.

    <script language="JavaScript">
    <!-- Hide from old browsers

    var imagenumber = 5 ;
    var randomnumber = Math.random() ;
    var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
    images = new Array
    images[1] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/airmax.jpg"
    images[2] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezblade.jpg"
    images[3] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/esav.jpg"
    images[4] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/wobble.jpg"
    images[5] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezglass.jpg"
    var image = images[rand1]

    links = new Array
    links[1] = "http://10.1.1.168/Hunter/consumerSite/features/airmax.php"
    links[2] = "http://10.1.1.168/Hunter/consumerSite/features/ez-blades.php"
    links[3] = "http://10.1.1.168/Hunter/consumerSite/features/energysav.php"
    links[4] = "http://10.1.1.168/Hunter/consumerSite/features/wobblefree.php"
    links[5] = "http://10.1.1.168/Hunter/consumerSite/features/ez-glass.php"
    var link = links[rand1]// -- End Hiding Here -->

    </script>


    <script language="JavaScript">
    <!-- Hide this script from old browsers -->
    document.write('<A HREF="' + link + '"><IMG SRC="' + image + '" border="0"></a>')
    <!-- End Hiding Here -->
    </script>

  2. #2
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    <script language="JavaScript">
    <!-- Hide from old browsers

    var imagenumber = 5 ;
    var randomnumber = Math.random() ;
    var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
    images = new Array
    images[1] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/airmax.jpg"
    images[2] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezblade.jpg"
    images[3] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/esav.jpg"
    images[4] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/wobble.jpg"
    images[5] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezglass.jpg"
    var image = images[rand1]

    links = new Array
    links[1] = "http://10.1.1.168/Hunter/consumerSite/features/airmax.php"
    links[2] = "http://10.1.1.168/Hunter/consumerSite/features/ez-blades.php"
    links[3] = "http://10.1.1.168/Hunter/consumerSite/features/energysav.php"
    links[4] = "http://10.1.1.168/Hunter/consumerSite/features/wobblefree.php"
    links[5] = "http://10.1.1.168/Hunter/consumerSite/features/ez-glass.php"
    var link = links[rand1]// -- End Hiding Here -->

    </script>


    <script language="JavaScript">
    <!-- Hide this script from old browsers -->
    newwindow=window.open("","");

    newwindow.write('<A HREF="' + link + '"><IMG SRC="' + image + '" border="0"></a>')
    <!-- End Hiding Here -->
    </script>

  3. #3
    Join Date
    Mar 2003
    Posts
    2
    Thanks for the help, but it still doesn't seem to work right.
    the random image needs to load in the same window, not a popup. When the random image loads thought, once you click on it, then that url will open up in a new window. I don't know if that makes sense or not.
    anyway, thanks for your help.

  4. #4
    Join Date
    Mar 2003
    Posts
    4
    Not a problem, really. What you would do is throw this part of the script into a webpage:

    <script language="JavaScript">
    <!-- Hide from old browsers

    var imagenumber = 5 ;
    var randomnumber = Math.random() ;
    var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
    images = new Array
    images[1] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/airmax.jpg"
    images[2] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezblade.jpg"
    images[3] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/esav.jpg"
    images[4] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/wobble.jpg"
    images[5] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezglass.jpg"
    var image = images[rand1]

    links = new Array
    links[1] = "http://10.1.1.168/Hunter/consumerSite/features/airmax.php"
    links[2] = "http://10.1.1.168/Hunter/consumerSite/features/ez-blades.php"
    links[3] = "http://10.1.1.168/Hunter/consumerSite/features/energysav.php"
    links[4] = "http://10.1.1.168/Hunter/consumerSite/features/wobblefree.php"
    links[5] = "http://10.1.1.168/Hunter/consumerSite/features/ez-glass.php"
    var link = links[rand1]// -- End Hiding Here -->

    </script>

    Then, at the appropriate part of the same page, you'd put the other script in, with a bit of modification:


    <script language="JavaScript">
    <!-- Hide this script from old browsers -->
    document.write('<A HREF="' + link + '" TARGET="_blank"><IMG SRC="' + image + '" border="0"></a>')
    <!-- End Hiding Here -->
    </script>

    the target part of the <a> tag will open a new window when the link is clicked.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles