| View previous topic :: View next topic |
| Author |
Message |
XabbaRus
Joined: 21 Sep 2001 Posts: 6949
|
Posted: Fri Feb 11, 2005 4:57 pm Post subject: Help with Javascript I found |
|
|
OK here is the script I found but I am having difficulty working out what to replace to get it to work
<script language="Javascript">
<!--
// original content taken from Nic's JavaScript Page with permission
// lack of these three lines will result in copyright infringment
// made by: Nic's JavaScript Page - http://www.javascript-page.com
var currentdate = 0;
var core = 0;
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}
link = new initArray(
"http://3bgraphics.hypermart.net/",
"http://html.digitalsea.net/",
"http://www.javascript-page.com/"
);
image = new initArray(
"http://3bgraphics.hypermart.net/link/3bgraphics.gif",
"http://html.digitalsea.net/htmlnow.gif",
"http://www.geocities.com/~jsmaster/jsnow.gif"
);
text = new initArray(
"3B Graphics",
"Learn HTML in 7 Easy Steps",
"Nic's JavaScript Page"
);
var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink = link[core];
var ranimage = image[core];
var rantext = text[core];
document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');
//-->
</SCRIPT>
I am guessing here: link = new initArray is where I put my webpage address.
And here: image = new initArray is where I put the url for where my graphics reside.
As I am not needing text I don't need the text bit. However I am confused as to the document.write section. What do I put here?
Cheers. |
|
| Back to top |
|
 |
Jesper
Joined: 14 Sep 2002 Posts: 2063 Location: Denmark (GMT+01.00)
|
Posted: Sat Feb 12, 2005 4:30 am Post subject: |
|
|
change <script language="Javascript">
to <script type="text/javascript">
this section is where you banners links to and should match the next section 1 by 1
//LINKS SECTION
link = new initArray(
"http://3bgraphics.hypermart.net/",
"http://html.digitalsea.net/",
"http://www.javascript-page.com/"
);
//BANNER/IMAGES SECTION
image = new initArray(
"http://3bgraphics.hypermart.net/link/3bgraphics.gif",
"http://html.digitalsea.net/htmlnow.gif",
"http://www.geocities.com/~jsmaster/jsnow.gif"
);
eg
1st link subsim
2nd link this link
3rd link that link
4th....
):
1st banner subsim.jpg
2nd banner this img
3rd banner that img
4th....
);
if you dont want alt text simply change
document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');
to
document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=""></a>');
if you dont want to open in a new window remove target aswell
document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=""></a>');
if you want to force a size of 468x60px add width="468" height="60"
document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" width="468" height="60" alt=""></a>'); |
|
| Back to top |
|
 |
XabbaRus
Joined: 21 Sep 2001 Posts: 6949
|
Posted: Sat Feb 12, 2005 8:17 am Post subject: |
|
|
So my modified script should look like this:
My links are in red.
Also exactly where do I place stuff in the +ranimage+ section. I tried it but no go.
If it works properly then each time someone loads up m y page they should get either the DSRV image or the Type42 one?
<script language="Javascript">
<!--
// original content taken from Nic's JavaScript Page with permission
// lack of these three lines will result in copyright infringment
// made by: Nic's JavaScript Page - http://www.javascript-page.com
var currentdate = 0;
var core = 0;
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}
link = new initArray(
"http://hompages.tesco.net/benedict.kent",
"http://html.digitalsea.net/",
"http://www.javascript-page.com/"
);
image = new initArray(
"http://hompages.tesco.net/benedict.kent/Buttons/Mainimage.png",
"http://hompages.tesco.net/benedict.kent/Buttons/DSRV.jpg"
);
text = new initArray(
"3B Graphics", <REMOVE THESE>
"Learn HTML in 7 Easy Steps",
"Nic's JavaScript Page" );
var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink = link[core];
var ranimage = image[core];
var rantext = text[core];
document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');
//-->
</SCRIPT> |
|
| Back to top |
|
 |
Jesper
Joined: 14 Sep 2002 Posts: 2063 Location: Denmark (GMT+01.00)
|
Posted: Mon Feb 14, 2005 1:25 pm Post subject: |
|
|
Sorry for the late reply, have been with the wench since sat noon.
Yeah it should work,, you have to place the script where you want it on the page.
eg if you want it in the top of the page:
| Code: | !DOCTYPE.......
<html>
<head>
<title></title>
</head>
<body>
<center><JAVA SCRIPT HERE></SCRIPT></center>
WEB PAGE CONTENT HERE>
</body>
</html> |
I would assume you need as many banners and texts as you have links. (3 in your example above)
Ill make a super quick sample in a few minutes m8  |
|
| Back to top |
|
 |
Jesper
Joined: 14 Sep 2002 Posts: 2063 Location: Denmark (GMT+01.00)
|
Posted: Mon Feb 14, 2005 2:16 pm Post subject: |
|
|
Here you go mate
http://luvaduck.homelinux.org/javascript.php
ps dont press the xHTML button, if you want it to follow the RFC ill fix it up for you, the button is just part of my standard footer!  |
|
| Back to top |
|
 |
XabbaRus
Joined: 21 Sep 2001 Posts: 6949
|
Posted: Mon Feb 14, 2005 5:30 pm Post subject: |
|
|
| I only need the one link as it is just to change the title picture each time. |
|
| Back to top |
|
 |
XabbaRus
Joined: 21 Sep 2001 Posts: 6949
|
Posted: Mon Feb 14, 2005 5:41 pm Post subject: |
|
|
In fact I don't need a link at all.
All i want is the main picture to change each time...
OK it is working....just how do I stop the pic being a link? |
|
| Back to top |
|
 |
XabbaRus
Joined: 21 Sep 2001 Posts: 6949
|
Posted: Wed Feb 16, 2005 2:33 pm Post subject: |
|
|
So Jepser in that code what do I need to delete to stop it thinking the image is a link and still display it with no problems?
I tried fiddling around but had to go back to making it a link. |
|
| Back to top |
|
 |
Jesper
Joined: 14 Sep 2002 Posts: 2063 Location: Denmark (GMT+01.00)
|
Posted: Wed Feb 16, 2005 2:46 pm Post subject: |
|
|
Just change this:
| Code: | | document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" width="468" height="60" border="0" alt=\"'+rantext+'\"></a>'); |
to
| Code: | | document.write('<img src=\"'+ranimage+'\" width="468" height="60" border="0" alt="">'); |
|
|
| Back to top |
|
 |
XabbaRus
Joined: 21 Sep 2001 Posts: 6949
|
Posted: Wed Feb 16, 2005 5:05 pm Post subject: |
|
|
Excellent,
Cheers for all your help Jesper.
Now I might do the same for the small image... |
|
| Back to top |
|
 |
|