Forum Moderators: open

Message Too Old, No Replies

Random background image Javascript Problem

Dreamweaver Template wrinkle? or crappy code?

         

The_Hat

2:48 am on May 25, 2004 (gmt 0)

10+ Year Member



So I have a page I built in DW with a top of page header (logo and company name etc.) In the header I have a bit of java that loads a random background image. It is a really nice looking touch. When I go to save that page out as a template in Dream Weaver the java bit breaks and no image shows at all. I have
<script language="JavaScript" src="../random.js"></script>
in the head of the page
that calls a .js file that says

var randnum = Math.random();
var inum = 2;
// Change this number to the number of images you are using.
var rand1 = Math.round(randnum * (inum-1)) + 1;
images = new Array
images[1] = "images/random1.gif"
images[2] = "images/random2.gif"
// Ensure you have an array item for every image you are using.
var image = images[rand1]

In the page I have.

<script language="JavaScript">
<!-- Activate cloaking device
document.write('<td background="'+image+'">')
// Deactivate cloaking device -->
</script>

Where i want the effect to display.

Works fine when it is just a page. Soon as I save the page as a DW template it beaks.

Any ideas? I have no idea what I am doing.
Thanks in advance.

sullen

8:44 am on May 25, 2004 (gmt 0)

10+ Year Member



Yes, Dreamweaver does that kind of thing.

It might help if you add semicolons to the ends of the lines that currently don't have them.

Or you'll have to create the template without the javascript and then paste it into all the pages when you've finished.

MichaelBluejay

9:41 am on May 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To be picky, your code is JavaScript, not Java. They're *completely* different. I know it doesn't matter in this case because it's clear enough what you really mean, but if you go around saying Java when you mean JavaScript then someday someone will take you at your word and there will be a big disconnect.

As for your problem, it seems pretty clear that Dreamweaver is messing it up. What I suggest is loading the messed-up page in a browser and then do a "View Source", and take a look at the code, and see exactly what and how Dreamweaver changed it. Once you know how it's being munged that might give you clue as to how to fix it.

Another possibility is to move the call out of the head and put it directly in the BODY, where you want the image to appear. And take out that code that draws the image and stick that in the .js file so the only thing in your document is the call to the file that draws the whole thing.