Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 2.67 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-26-2004, 11:08 PM   PM User | #1
Blade376
New to the CF scene

 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Blade376 is an unknown quantity at this point
Unhappy Help please ASAP! In desperate need!

Hi! I am making my bands website, n i though this template would make my vision easy to do..but it hasn't worked out how i'd of liked it to.

www.penitentiary.co.uk

I have already put the other half of the script in, but it is this part which is wrong. It is script so that every time the home page is visited, 1 of 6 images appears at random adding variety...however, 4 of the images link to different areas of the site (this is possible?) I guess it's cause i've used HTML coding in it, but i know nothing of java.

Below is the script..if you could help me based on what I offer you, or even correct it for me, i'd be so appriciative..as i'm pulling my hair out over this.

~Blade376



<script language="JavaScript" type="text/javascript">
// This script was supplied free by Hypergurl
// http://www.**************
<!--
// JavaScript to interpolate random images into a page.
var ic = 6; // Number of alternative images
var xoxo = new Array(ic); // Array to hold filenames

xoxo[0] = "http://www.penitentiary.co.uk/Home%20Page%20Adverts/13th%20March%20Gig%20Edit.jpg";
xoxo[1] = "http://www.penitentiary.co.uk/Home%20Page%20Adverts/EPADlarge.jpg";
xoxo[2] = <p align="center"><a href="http://www.penitentiary.co.uk/EPcoverdesigns.htm"><img src="http://www.penitentiary.co.uk/Home%20Page%20Adverts/epcoverdesignAD.jpg"></a>;
xoxo[3] = <p align="center"><a href="http://www.penitentiary.co.uk/Flyers.htm"><img src="http://www.penitentiary.co.uk/Home%20Page%20Adverts/FlyersADlarge.jpg"></a>;
xoxo[4] = <p align="center"><a href="http://www.penitentiary.co.uk/forum/index.php"><img src="http://www.penitentiary.co.uk/Home%20Page%20Adverts/ForumADlarge.jpg"></a>;
xoxo[5] = <p align="center"><a href="http://www.penitentiary.co.uk/news.htm"><img src="http://www.penitentiary.co.uk/Home%20Page%20Adverts/MailinglistADlarge.jpg"></a>;

function pickRandom(range) {
if (Math.random)
return Math.round(Math.random() * (range-1));
else {
var now = new Date();
return (now.getTime() / 1000) % range;
}
}
// Write out an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(ic);
// -->
</script>
Blade376 is offline   Reply With Quote
Old 08-26-2004, 11:21 PM   PM User | #2
Blade376
New to the CF scene

 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Blade376 is an unknown quantity at this point
I found this, but it says configure images to corresponding links...how do i do that?


-----------

<script language="JavaScript">
<!--

/*
Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
Over 400+ free JavaScripts here!
Keep this notice intact please
*/

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
Blade376 is offline   Reply With Quote
Old 08-26-2004, 11:31 PM   PM User | #3
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Ahhh, one of HyperGirl's stolen and plagiarized scripts....
No offense, but that script is not worth fixing...

You can try my Random Image Link script...
It should be somewhat easier to use and also has the benifit of being reused several times on a page without duplicating any of the image/links...

To install, simply place the script into the HEAD of your document... Add your images and links by following the examples and where you would like a random image to appear add this script call: <script>randomLink()</script>

Code:
<script type="text/javascript">
 var myNumbers = [];
  function randomLink(){ 
   var theLinks = [// ADD YOUR IMAGES AND LINKS BELOW //;
                  [ 'images/image0.jpg' , 'site0.html' ], 
                  [ 'images/image1.jpg' , 'site1.html' ],
                  [ 'images/image2.jpg' , 'site2.html' ],
                  [ 'images/image3.jpg' , 'site3.html' ],
                  [ 'images/image4.jpg' , 'site4.html' ],
                  [ 'images/image5.jpg' , 'site5.html' ],
                  [ 'images/image6.jpg' , 'site6.html' ],
                  [ 'images/image7.jpg' , 'site7.html' ],
                  [ 'images/image8.jpg' , 'site8.html' ],
                  [ 'images/image9.jpg' , 'site9.html' ]
                  ]// NO NEED TO EDIT BELOW THIS LINE //;


   var theNumber = Math.round(Math.random()*(theLinks.length-1));
    if(myNumbers.length < theLinks.length){
      for(var count=0; count<myNumbers.length; count++){ 
        while(theNumber == myNumbers[count]){
           theNumber = Math.round(Math.random()*(theLinks.length-1));
           count = 0;
        }
      }    myNumbers.push(theNumber);
    } 

    else{theNumber = 0};
     var  anchor = '<a class="random" href="'+theLinks[theNumber][1]+'">';
          anchor+= '<img src="'+theLinks[theNumber][0]+'"></a>';
          document.writeln(anchor);
  }
</script>
</head>

<body>
<script>randomLink()</script><br>
<script>randomLink()</script><br>
<script>randomLink()</script><br>
<script>randomLink()</script><br>
.....Willy
Willy Duitt is offline   Reply With Quote
Old 12-13-2004, 11:58 PM   PM User | #4
junip
New to the CF scene

 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
junip is an unknown quantity at this point
I tried your code Willi and it worked great in Netscape and Safari, but not in Explorer 5.2.3. I'm coding on a mac (as I am a graphic designer), so that is the latest IE version available to me.

Is there anything I can do to this code to make it work in IE for mac?

Thanks in advance
junip is offline   Reply With Quote
Old 12-14-2004, 10:43 AM   PM User | #5
jbot
Senior Coder

 
Join Date: Feb 2004
Location: Edinburgh
Posts: 1,352
Thanks: 0
Thanked 0 Times in 0 Posts
jbot is an unknown quantity at this point
Quote:
Originally Posted by junip
Is there anything I can do to this code to make it work in IE for mac?
ignore Mac IE, it's a POS. seriously, M$ have stopped supporting it, so why should you. IE on the Mac is so bug ridden I'm surprised the UN haven't banned it under the Biological Weapons Convention.

best thing to do is to trap its users and instruct them to use another browser.
__________________
*keep it simple (TM)
jbot is offline   Reply With Quote
Old 12-14-2004, 12:31 PM   PM User | #6
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Array.push method is not supported in IE Mac. You need to add this in your page:
Code:
if(typeof Array.prototype.push=='undefined')
    Array.prototype.push=function(){
        var
            i=0,
            b=this.length,
            a=arguments;
        for(i;i<a.length;i++)
            this[b+i]=a[i];
        return this.length
    };
For other array functionalities not fully implemented by some browsers, please refer to this.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 08-17-2006, 01:35 PM   PM User | #7
hewsy10
New to the CF scene

 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hewsy10 is an unknown quantity at this point
Without Links?

Hey!

This is really an excellent script. I want to use it for a project of mine but I don't need the links ... just the images. What is the best way of removing the links?

Also, there is a blue border around each image. I guess this will be removed if I remove the links?

Thanks a lot.
hewsy10 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:28 PM.


Advertisement
Log in to turn off these ads.