Results 1 to 2 of 2

Thread: Javascript random im age on refresh with links and targets

  1. #1
    Join Date
    Dec 2009
    Posts
    54
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Javascript random im age on refresh with links and targets

    hi all,

    im looking for a script to allow random images to change but to have them as indervidual links that go to different places and also have them all going to different targets

    e.g

    image1.jpg > _blank
    image2.jpg > _self
    image3.jpg > _blank
    image3.jpg > _blank

    thanks in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    Code:
    <div id="randomLnks">
    <a href="someDefault.htm" target="someDefaultTarget"><img src="someDefault.jpg" alt="Some Default Alt Text" title=""></a>
    </div>
    <script type="text/javascript">
    (function(){
    	var imgLnkTrgs = [], targDiv = document.getElementById('randomLnks').getElementsByTagName('*');
    	imgLnkTrgs[0] = ['image1.jpg', 'http://www.somedomain.com/', '_blank'];
    	imgLnkTrgs[1] = ['image2.jpg', 'some.htm', '_self'];
    	imgLnkTrgs[2] = ['image3.jpg', 'http://www.anotherdomain.com/', '_blank'];
    	imgLnkTrgs[3] = ['image4.jpg', 'http://www.yetanotherdomain.com/', '_blank'];
    	imgLnkTrgs = imgLnkTrgs[Math.floor(Math.random() * imgLnkTrgs.length)];
    	targDiv[0].href = imgLnkTrgs[1];
    	targDiv[0].target = imgLnkTrgs[2];
    	targDiv[1].src = imgLnkTrgs[0];
    	targDiv[1].alt = 'Random Image w/Link';
    })();
    </script>
    - John
    ________________________

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

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
  •