PDA

View Full Version : Firing an artificial load event for window



timaddison
10-20-2007, 05:32 PM
Main DD Script:
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Just a quick (I hope!) question. I'm making a site which injects content into a container div via the above script, and also makes use of the loadobjs method to load javascript and style sheets where relevant.

The trouble I have is that some of the javascripts (lightbox and effects, prototype framework) rely on the window load event to instantiate the classes I need.

And when the scripts are loaded via ajax they run but the neccesary trigger which instantiates the classes isn't hit, and I wondered if I could fire another Window.load event?

So far my searching and experimentation has got me nowhere, and I wondered if anyone knew of a workaround (constrained by loading the scripts at an arbitary point after the initial page had loaded)?

Thanks,

Tim

Twey
10-20-2007, 05:33 PM
http://www.howtocreate.co.uk/tutorials/javascript/domevents

timaddison
10-20-2007, 05:47 PM
Thanks for the quick reply, reading through it seems that the only object I can't use fireEvent on is the window object, guess I'll have to see if i can hack the scripts to be reliant on the document objects load instead :)

jscheuer1
10-21-2007, 04:26 PM
If you are using:

http://www.dynamicdrive.com/dynamicindex4/lightbox2/index.htm

You don't really want to re-init it over and over again. That would (in addition to initializing imported links) also add the lightbox framework elements to the page each time, confusing the heck out of many browsers.

With lightbox and Ajax, I've been recommending this approach -

Put the lightbox scripts and style links on the top page. On your external pages, use the hard coded onclick event with each lightbox link, ex (from the demo page, addition red):


<a href="images/image-1.jpg" rel="lightbox" onclick="myLightbox.start(this); return false;" title="my caption">image #1</a>