473,597 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random image script with link, alt, and title attributes

I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this?

Here's the script I found:
Thanks

<script language="JavaS cript">
<!--

/*
Random Image Link Script- By JavaScript Kit(http://www.javascriptkit.com)
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/

function random_imglink( ){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="../images/s01.jpg"
myimages[2]="../images/s02.jpg"
myimages[3]="../images/s03.jpg"
myimages[4]="../images/s04.jpg"
myimages[5]="../images/s05.jpg"
myimages[6]="../images/s06.jpg"

//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="../photos/01.html"
imagelinks[2]="../photos/02.html"
imagelinks[3]="../photos/03.html"
imagelinks[4]="../photos/04.html"
imagelinks[5]="../photos/05.html"
imagelinks[6]="../photos/06.html"

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

--
Olly

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 23 '05 #1
6 3516
sorry I missed this off, but if possible could it also be in a *.js file?

On Tue, 25 May 2004 16:49:11 +0100, Olly <ol********@yah oo.co.uk> wrote:
I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this?

Here's the script I found:
Thanks

<script language="JavaS cript">
<!--

/*
Random Image Link Script- By JavaScript Kit(http://www.javascriptkit.com)
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/

function random_imglink( ){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="../images/s01.jpg"
myimages[2]="../images/s02.jpg"
myimages[3]="../images/s03.jpg"
myimages[4]="../images/s04.jpg"
myimages[5]="../images/s05.jpg"
myimages[6]="../images/s06.jpg"

//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="../photos/01.html"
imagelinks[2]="../photos/02.html"
imagelinks[3]="../photos/03.html"
imagelinks[4]="../photos/04.html"
imagelinks[5]="../photos/05.html"
imagelinks[6]="../photos/06.html"

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


--
Olly

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 23 '05 #2
Lee
Olly said:

sorry I missed this off, but if possible could it also be in a *.js file?

On Tue, 25 May 2004 16:49:11 +0100, Olly <ol********@yah oo.co.uk> wrote:
I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this?

Here's the script I found:


[snipped]

You found some remarkably bad code.

Here's one solution that includes alt and title attributes.
The script block that I've put in the head could be placed into
a .js file. remember not to include the <script> and </script>
HTML tags in the .js file. The block that would appear in the
head would look something like:

<script type="text/javscript" src="../myscripts/myimgscript.js> </script>

The small script block I've placed in the body can be placed
wherever you want the random link to appear.

You can use more than one random link in the page without
reusing any until you've used them all. After that, the
last link will repeat.
<html>
<head>
<script type="text/javascript">

var myimages = [
{ src : "../images/s01.jpg",
link : "../photos/01.html",
alt : "Alt Text 01",
title : "Title 01"
},

{ src : "../images/s02.jpg",
link : "../photos/02.html",
alt : "Alt Text 02",
title : "Title 02"
},

{ src : "../images/s0n.jpg",
link : "../photos/0n.html",
alt : "Alt Text 0n",
title : "Title 0n"
}
];
function random_imglink( ){
var ry=Math.floor(M ath.random()*my images.length)
document.write( '<a href="'+myimage s[ry].link
+'"><img src="'+myimages[ry].src
+'" alt="'+myimages[ry].alt
+'" title="'+myimag es[ry].title
+' " border=0></a>');
if(myimages.len gth>1){
myimages[ry]=myimages[myimages.length-1];
myimages.length--;
}
}
</script>
</head>
<body>
Here's the link: <script type="text/javascript">ran dom_imglink()</script>
</body>
</html>

Jul 23 '05 #3
Thanks, the script works if the full code is placed in the head of the
document. However, if a link to a *.js file is used it doesn't work.

My *.html document code:
<script src="../random.js" type="text/javscript"></script>
</head>
<body>
<script type="text/javascript">ran dom_imglink()</script>

My random.js document code:
// Generated by AceHTML Freeware http://freeware.acehtml.com
// Creation date: 2004-05-25

var myimages = [
{ src : "images/s01.jpg",
link : "photos/01.html",
alt : "Alt Text 01",
title : "Title 01"
},

{ src : "images/s02.jpg",
link : "photos/02.html",
alt : "Alt Text 02",
title : "Title 02"
},

{ src : "images/s0n.jpg",
link : "photos/0n.html",
alt : "Alt Text 0n",
title : "Title 0n"
}
];
function random_imglink( ){
var ry=Math.floor(M ath.random()*my images.length)
document.write( '<a href="'+myimage s[ry].link
+'"><img src="'+myimages[ry].src
+'" alt="'+myimages[ry].alt
+'" title="'+myimag es[ry].title
+' " border=0></a>');
if(myimages.len gth>1){
myimages[ry]=myimages[myimages.length-1];
myimages.length--;
}
}

On 25 May 2004 10:05:32 -0700, Lee <RE************ **@cox.net> wrote:
Olly said:

sorry I missed this off, but if possible could it also be in a *.js
file?

On Tue, 25 May 2004 16:49:11 +0100, Olly <ol********@yah oo.co.uk> wrote:
I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this?

Here's the script I found:


[snipped]

You found some remarkably bad code.

Here's one solution that includes alt and title attributes.
The script block that I've put in the head could be placed into
a .js file. remember not to include the <script> and </script>
HTML tags in the .js file. The block that would appear in the
head would look something like:

<script type="text/javscript" src="../myscripts/myimgscript.js> </script>

The small script block I've placed in the body can be placed
wherever you want the random link to appear.

You can use more than one random link in the page without
reusing any until you've used them all. After that, the
last link will repeat.


[snipped]

--
Olly

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 23 '05 #4
Olly wrote:
I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this?

Here's the script I found:
Thanks

<script language="JavaS cript">
<script type="text/javascript">
<!--
Not needed.
/*
Random Image Link Script- By JavaScript Kit(http://www.javascriptkit.com)
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/

function random_imglink( ){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="../images/s01.jpg"
myimages[2]="../images/s02.jpg"
myimages[3]="../images/s03.jpg"
myimages[4]="../images/s04.jpg"
myimages[5]="../images/s05.jpg"
myimages[6]="../images/s06.jpg"
Arrays start at 0 in Javascript, by starting at 1, the author of this script
ended up using a hack at the later that results in the first image appearing
more often then the rest.

var myimages = [
"../images/s01.jpg",
"../images/s02.jpg",
"../images/s03.jpg",
"../images/s04.jpg",
"../images/s05.jpg",
"../images/s06.jpg"
];
//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="../photos/01.html"
imagelinks[2]="../photos/02.html"
imagelinks[3]="../photos/03.html"
imagelinks[4]="../photos/04.html"
imagelinks[5]="../photos/05.html"
imagelinks[6]="../photos/06.html"
var imagelinks = [
"../photos/01.html",
"../photos/02.html",
"../photos/03.html",
"../photos/04.html",
"../photos/05.html",
"../photos/06.html"
];

New code:

var imagealts = [
"alt text 1",
"alt text 2",
"alt text 3",
"alt text 4",
"alt text 5",
"alt text 6"
];

var imagetitles = [
"image title 1",
"image title 2",
"image title 3",
"image title 4",
"image title 5",
"image title 6"
];
var ry=Math.floor(M ath.random()*my images.length)
if (ry==0)
ry=1
Replace this all with:

var img = Math.floor(myim ages.length * Math.random());
document.write( '<a href='+'"'+imag elinks[ry]+'"'+'><img
src="'+myimages[ry]+'" border=0></a>')
}
document.write(
'<a href="' + imagelinks[img] + '"><img src="' +
myimages[img] + '" border="0" alt="' +
imagealts[img] + '" title="' +
imagetitles[img] + '"></a>'
);
random_imglink( )
I have no idea what this does. You don't have the function random_imglink( )
defined in the code you showed us. Perhaps the document.write( ) was once done
in "random_imglink ()"? If so, you're now doing the document.write( ) as inline
Javascript, the function call is no longer required.
//-->
Not needed.
</script>

--
Olly

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #5
Grant Wagner <gw*****@agrico reunited.com> writes:

function random_imglink( ){

.... random_imglink( )


I have no idea what this does. You don't have the function random_imglink( )
defined in the code you showed us.


Easy to miss in the this badly indented source (although that might
not be the author's fault, but come from copying from a web page).

So, the code simply defines a function and then calls it. While
only polluting the namespace with one function, it could just as
well be done with an anonymous function.
Otherwise, I agree completely.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6
Thanks it works great!!

On Tue, 25 May 2004 18:12:40 GMT, Grant Wagner
<gw*****@agrico reunited.com> wrote:
Olly wrote:
I've found a basic script, however I also need to add alt and title
attributes as well, how would I go about doing this?

Here's the script I found:
Thanks

<script language="JavaS cript">


<script type="text/javascript">
<!--


Not needed.
/*
Random Image Link Script- By JavaScript
Kit(http://www.javascriptkit.com)
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/

function random_imglink( ){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="../images/s01.jpg"
myimages[2]="../images/s02.jpg"
myimages[3]="../images/s03.jpg"
myimages[4]="../images/s04.jpg"
myimages[5]="../images/s05.jpg"
myimages[6]="../images/s06.jpg"


Arrays start at 0 in Javascript, by starting at 1, the author of this
script
ended up using a hack at the later that results in the first image
appearing
more often then the rest.

var myimages = [
"../images/s01.jpg",
"../images/s02.jpg",
"../images/s03.jpg",
"../images/s04.jpg",
"../images/s05.jpg",
"../images/s06.jpg"
];
//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="../photos/01.html"
imagelinks[2]="../photos/02.html"
imagelinks[3]="../photos/03.html"
imagelinks[4]="../photos/04.html"
imagelinks[5]="../photos/05.html"
imagelinks[6]="../photos/06.html"


var imagelinks = [
"../photos/01.html",
"../photos/02.html",
"../photos/03.html",
"../photos/04.html",
"../photos/05.html",
"../photos/06.html"
];

New code:

var imagealts = [
"alt text 1",
"alt text 2",
"alt text 3",
"alt text 4",
"alt text 5",
"alt text 6"
];

var imagetitles = [
"image title 1",
"image title 2",
"image title 3",
"image title 4",
"image title 5",
"image title 6"
];
var ry=Math.floor(M ath.random()*my images.length)
if (ry==0)
ry=1


Replace this all with:

var img = Math.floor(myim ages.length * Math.random());
document.write( '<a href='+'"'+imag elinks[ry]+'"'+'><img
src="'+myimages[ry]+'" border=0></a>')
}


document.write(
'<a href="' + imagelinks[img] + '"><img src="' +
myimages[img] + '" border="0" alt="' +
imagealts[img] + '" title="' +
imagetitles[img] + '"></a>'
);
random_imglink( )


I have no idea what this does. You don't have the function
random_imglink( )
defined in the code you showed us. Perhaps the document.write( ) was once
done
in "random_imglink ()"? If so, you're now doing the document.write( ) as
inline
Javascript, the function call is no longer required.
//-->


Not needed.
</script>

--
Olly

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html


--
Olly

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
9682
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to call that in another page so that i get a random image the page is http://2006ymcanationals.com/index.php using <img
4
16199
by: Kenny | last post by:
I have been trying to write a script that will increase the size of and image when you mouse over it, and decrease it to original size, when you mouse out. After a couple of attempts, this is what I've come up with. In this example, there are 5 images (0 thru 4) all with a height of 80px. When you mouse over an image, it changes the growingImage variable equal to the number of the image you mouse over, when you mouse out, it sets it to 5,...
3
7153
by: bigoxygen | last post by:
Hi. I have a list that is similar to this: -Evaluation +test +test -Students +test I would like to change the "-" bullet only, but I cannot. My
2
2310
by: tmb | last post by:
- Want to open a 2nd browser window when someone clinks a link with the link content inside it. - Want to control window size - Want all tool bars so only blue bar at top shows - Can I put my content in the blue bar? - Only options are Minimize, Maximize or Close (top right of blue bar) 1 - What is the difference in 'OpenWindow' and 'Spawn' ?? 2 - Can anyone point me to a simple script I can use... or just post one...
3
7048
by: Robert | last post by:
Hi, I'm trying to make a slide show, with two frames: on the left frame small thumbnails, and on the right frame the big sized image. Of course when the user clicks on a thumbnail in the left frame, this image should be shown in the right frame. As I have a large number of pictures I don't want to have a separate page for each picture, and use javascript instead. I would like to use this in the left frame (see full code below):
14
1786
by: Mario | last post by:
I wrote a tooltips script. I've noticed "small" problem occuring while using the IE browser. If a site is long enough for a scroll to appear and we move the mouse indicator on the link then the scroll "jumps" for a second and goes back to the previous position. I haven't seen it in other scripts. I have no idea what is wrong... I enclose my script full of <br /> index in order to scroll appearance.
14
11062
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
4
2743
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
1
1965
by: bn4 | last post by:
I have been trying to modify a script that i had working in the past but have lost.. ORIGINAL URL: http://www.thescripts.com/forum/thread147097.html STEPS: I want it to do the following: 1-Load a Random Image each time page loads or is refreshed / script starts (with corresponding url link when clicked) 2-Images change by blend/fade into one another, on an adjustable time delay 3-Next image loaded also loads new corresponding url/link
0
7977
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8276
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8261
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3936
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1496
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.