JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 24th, 2001, 08:40 AM
Lattimer Lattimer is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Utah
Posts: 1 Lattimer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Lattimer
Exclamation

Maybe not a god, but here goes....

I'm working on a new design using HeirMenus for navigation. The script calls 2 external .js files that hold the array and the menu configuration. Now, as most designers know, you can't use an onload event in 2 different places on a page, they conflict and one won't work. OK- so I have the heir menus and a DHTML text scroller that need loaded. However, the Heir menus don't use a standard window.onload or body onload to call the script. The script uses this: (cut and paste from FAQ regarding this subject)


"The HM onload handler, as we know, calls the startIt() function:

loader.onload = startIt;

We must, therefore, make sure that one onload handler calls both startIt() and startTheOtherTechnique()! Many, if not most, DHTML techniques using an onload handler, begin a dynamic display when the page has loaded. Our fader, and Doc JavaScript's scroller, are two examples. The HM script, on the other hand, does not begin a technique, it simply creates more elements on the page. It, in essence, extends the load procedure and, consequently, should take precedence.

This means that the other script's onload handler should be cut from the page, and pasted into the end of the HM load function:

function startIt() {
isLoaded = true;
if (isFrames) {
menuLoc = eval("parent.frames." + mainFrName);
if (NS4) {
loader.captureEvents(Event.LOAD);
loader.onload = NSloaded;
menuLoc.onunload = NSunloaded;
}
if (IE4) {
menuLoc.document.body.onunload = IEunloaded;
}
}
else {
menuLoc = window;
}
menuLoc.nav = nav = window;
if (clickKill) {
if (NS4) menuLoc.document.captureEvents(Event.MOUSEDOWN);
menuLoc.document.onmousedown = clicked;
}
makeTop();

startTheOtherTechnique(arg1,arg2,...,argn); <-- paste here at end of startIt()
}
Now, the menus will be created, your page elements will be complete, and then your other technique will begin, with no conflict."


Sure! Sounds easy enough! Just slap it on in there! Too bad I can't get it to work! I'm not exactly an expert with Javascript, so I'm not sure how to add this to the code:


window.onload=startscroll


It's the last line in the script for the scroller...

Can someone PLEASE tell me how to do this! I've been pulling my hair out for 2 days on this one! Here's the page if you want to see the whole code:

URL

Thanks in advance!!!

Doug

Reply With Quote
  #2  
Old February 26th, 2001, 11:53 PM
rdominy rdominy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 81 rdominy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Send a message via ICQ to rdominy
I think you have a couple of options that should work pretty easily without resorting to trying to append your function call inside the other function, but you can do that too (see Method 3).

Method 1:
I assume that the onload handler is being set directly inside the included .js file. What you can do is simply write your own onload handler and have it call the other ones. For example, in pseudocode:

// include file 1, assuming it sets onload=includeload1
// include file 2, assuming it sets onload=includeload2

function myLoad()
{
includeload1();
includeload2();
}
window.onload = myLoad;

Method 2:
In the body tag it is possible specify multiple function calls separated by semicolons. Just place the needed calls here. Example:
<BODY onload="includeload1();includeload2()"

Method 3:
The most foolproof way to avoid clobbering other developers onload is to look for it and dynamically create a new function that calls it and yours. Example:

if (window.onload)
{
var loadStr = window.onload.toString();
var newLoadStr = loadStr.substring(loadStr.indexOf("{") + 1,newLoadStr.lastIndexOf("}") - 1) + "\r" + ";" + "myOnLoad()";
window.onload = new Function(newLoadStr);
}
else
window.onload = myOnLoad;

Hope that helps
- Bob


Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > I need a JavaScript GOD!!! HELP!!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap