Why does this code not work in a DWT? (Full Version)

All Forums >> [Web Development] >> Dreamweaver Help



Message


hoopsking -> Why does this code not work in a DWT? (9/29/2007 0:19:39)

Why does this code not work inside a DWT applied to a page? It's the Free Drills image rotator on the upper left side.

Here is a page without a DWT that it works in:http://www.advancedbasketballtraining.com/index_new.html
Here is a page WITH a DWT that it does not work in:http://www.advancedbasketballtraining.com/Basketball_Drills/Basketball_Defense_Drill.html

<script language="Javascript">
<!--
var currentdate = 0
var core = 0

function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this = ' '

}
}

image = new StringArray(2)
image[0] = '0.jpg'
image[1] = '1.jpg'
var ran = 60/image.length

function ranimage() {
currentdate = new Date()
core = currentdate.getSeconds()
core = Math.floor(core/ran)
return(image[core])
}

document.write("<img src='" +ranimage()+ "'>")

//-->
</script>
<!--/left menu --><br>




Tailslide -> RE: Why does this code not work in a DWT? (9/29/2007 3:01:28)

Not sure but my guess is it's the path to the image. It seems to be generating this for example:

<img src="1.jpg">


But the other page is in a lower folder so it should be this:

<img src="../1.jpg">


I think the easiest thing to do given that you want to use this script on multiple folders is to change the script so that it's like this:

document.write("<img src='/" +ranimage()+ "'>")
With the added "/" it means that the script will always go to the highest folder level to look for the images which is where they are.




hoopsking -> RE: Why does this code not work in a DWT? (9/29/2007 10:23:53)

Thank you. That worked.




hoopsking -> RE: Why does this code not work in a DWT? (9/29/2007 21:50:05)

Any idea on how to make one hyperlink open when the image is clicked?




Tailslide -> RE: Why does this code not work in a DWT? (9/30/2007 3:10:34)

What do you mean - open another window showing a larger version of the image or do you mean when an image is clicked then it goes to the relevant web page?

If it's the first one - I wouldn't do this, people don't like new windows opening it confuses them. The best solution if you want to show a larger version of an image is to use Lightbox 2 which is really easy to implement and gives a nice effect.

If you meant the second thing - basically making an image a link then it's simple, you do this:

<a href="yourpage.html"><img src="yourimage.jpg" alt="link to your page" width="whatever" height="whatever" /></a>


You will get a border around the image so you'll need to add this to your stylesheet:

img {border:none;}


Obviously you might sometimes want a border around an image so you might need to give these image links a class and then apply that rule to images with that class.




William Lee -> RE: Why does this code not work in a DWT? (9/30/2007 7:00:29)


quote:

ORIGINAL: Tailslide

What do you mean - open another window showing a larger version of the image or do you mean when an image is clicked then it goes to the relevant web page?

If it's the first one - I wouldn't do this, people don't like new windows opening it confuses them. The best solution if you want to show a larger version of an image is to use Lightbox 2 which is really easy to implement and gives a nice effect.

If you meant the second thing - basically making an image a link then it's simple, you do this:

<a href="yourpage.html"><img src="yourimage.jpg" alt="link to your page" width="whatever" height="whatever" /></a>


You will get a border around the image so you'll need to add this to your stylesheet:

img {border:none;}


Obviously you might sometimes want a border around an image so you might need to give these image links a class and then apply that rule to images with that class.


I'm learning... I'm learning.[;)]




hoopsking -> RE: Why does this code not work in a DWT? (9/30/2007 21:47:28)

I added the link code like this and the picture stopped displaying totally.


image = new StringArray(4)
image[0] = '0.jpg' <a href="http:/www.hoopsking.com"><img src="0.jpg" alt="link to your page" width="200" height="200" /></a>
image[1] = '1.jpg'
image[2] = '2.jpg'
image[3] = '3.jpg'




William Lee -> RE: Why does this code not work in a DWT? (9/30/2007 22:06:38)

quote:

ORIGINAL: hoopsking

I added the link code like this and the picture stopped displaying totally.


image = new StringArray(4)
image[0] = '0.jpg' <a href="http:/www.hoopsking.com"><img src="0.jpg" alt="link to your page" width="200" height="200" /></a>
image[1] = '1.jpg'
image[2] = '2.jpg'
image[3] = '3.jpg'



Try put it in the document.write like this:

document.write("<a href='http://www.outfront.net'><img src='/" +ranimage()+ "'/></a>")




Tailslide -> RE: Why does this code not work in a DWT? (10/1/2007 2:36:28)

No hang on - you've got an image link inside a JS array - that's not correct.

I didn't realise you were asking how to put a link inside the script rather than just make an image a link.

If you want the images to all go to exactly the same page then do what William suggested.

If you want different images to go to different pages then you'll need a more complex script like this one: http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm where you can specify different a different link for each image shown.




William Lee -> RE: Why does this code not work in a DWT? (10/1/2007 3:51:30)


Actually he almost got it there first time.
If different images link to different pages, I would suggest doing like this:


image[1]='<a href="http://www.yourdomain.com/page1.html"><img src="/images/1.jpg" alt="link to your page" width="whatever" height="whatever" /></a>'


and then in the document.write, just this:

document.write ranimage()

Worth a try. I can run fast, I'll be out of brickbat range if it doesn't work.[:D]




hoopsking -> RE: Why does this code not work in a DWT? (10/1/2007 10:38:07)

Thank you. I only wanted one link and it is now working.




William Lee -> RE: Why does this code not work in a DWT? (10/1/2007 21:45:49)


quote:

ORIGINAL: hoopsking

Thank you. I only wanted one link and it is now working.


I would really love to know if the second suggestion works. If you have the time to try it out, it will be greatly appreciated.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
6.445313E-02