Forum Moderators: phranque

Message Too Old, No Replies

onLoad elsewhere besides <body>?

         

Morgan19

10:17 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



I'm trying to get an imagemap working on my site but there's only one piece of the puzzle not working... The site was built using DW templates so I can't edit the < body > tags (it's a locked section), but I need to get this bit of code:

onload="preloadImages();">

...onto the page somehow. Can I put it anywhere else besides in the < body > tag? I just need to get that loaded to have the imagemap working, but this is driving me nuts since I can't get into the body tags.

m19

encyclo

10:22 pm on Dec 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not aware of any way of getting an onload event to work when not on the body element - although you might want to try putting it on an
img
to see if that works.

However, if you're talking about preloading a few images, have you tried using standard img links to each image, but with the width and height set to "1", placed somewhere unobtrusive (or in a div pushed off-screen with CSS)?

That should get the images downloaded and ready for your rollover, even if it is not a particularly elegant solution.

Morgan19

10:27 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Tried loading 1x1 versions of them but that didn't work. What exactly would I need to code to have it load on the img itself?

If not that, do you know of any way to unlock an area originally created with a locked area of a DW template...?

Or maybe some other bit of code that'll preload? Dunno, just seems like it's not working. :(

m19

Birdman

10:34 pm on Dec 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try adding this line in your JS script:

document.body.onload = preloadImages;

I believe that should work. It can go anywhere in the script, but keep it outside of any functions().

Birdman

Morgan19

10:38 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Didn't work. :(

And just to be sure, I tried it on the actual page as well as the imagemap HTML file (that just has the working imagemap). As soon as the onLoad is removed from the <body> tag, no matter what I've put elsewhere, the rollovers then don't work.

In case seeing the working imagemap.html file'll help, here it is:

<snip>

So that's the one that *does* work. This page is the one that I need to get the onLoad (or equivalent) working:

<snip>

Also, because of the "locked" areas, I've had to put the JS right after the opening <head> and title tag rather than after all the meta bits. Would that make a difference? (I thought I'd narrowed it down to the onLoad bit because the imagemap.html works fine until I removed the onLoad tag. And I've got everything else from the imagemap.html file in the index.html, except for the onLoad tag. o_O)

m19

[edited by: trillianjedi at 8:27 am (utc) on Dec. 3, 2004]
[edit reason] TOS - no URL's please [/edit]

Birdman

10:51 pm on Dec 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nah, I don't need to see it. I just tested my code and it didn't work for here either :(

However, this did: :)

onload = nameofyourfunctionhere;

Now, I could swear I used doc.body.onload before.

Morgan19

11:01 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



I'll try that out too, but... I think I might've gotten it working!

It sounds stupid, but instead of trying to get around the tempate, I just hunted through our archives... This site was originally created three or four years ago, but I eventually found the original template files, created a new one without the locked regions, and then was able to add the onLoad to the body tag. I'm testing now. :)

/crosses fingers

m19

instinct

11:18 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Dreamweaver also has "Editable Optional Regions" which would work in your case. Check the DW help files.

jollymcfats

5:49 am on Dec 3, 2004 (gmt 0)

10+ Year Member



You can also add an onload function like so:

if (window.addEventListener) { 
window.addEventListener('load', preloadImages, false);
} else if (window.attachEvent) {
window.attachEvent('onload', preloadImages);
}