PDA

View Full Version : Script conflict onload function



dmelosi
11-25-2007, 01:49 AM
1) Script Title: Script conflict onload function

2) Script URL (on DD): http://www.dealermanage.net/loginindex.asp

3) Describe problem: Hello,
If you hover over the bottom part of each link the drop down menu will come up.

I have a problem with conflicting JS scripts.

The problem is that on some pages I have within the page
onload="initializePage();" and some pages I do not.

The conflict occured and did not allow the navigation to show up on the pages that had within the page the onload="initializePage();"

The page calls on style.js to execute the navigation bar.

There is a place in the style.js to define onload functions.

I put initializePage(); in that area and it made the menu appear on all pages as wanted,

BUT now I get a java script error that says object expected on the pages WITHOUT the function within the page.

Any suggestions?

Thanks,
Dave

ddadmin
11-25-2007, 06:31 AM
I haven't looked at the source of Top Menu III (http://www.dynamicdrive.com/dynamicindex1/topmen3/index.htm) extensively yet, but assuming your problem is with multiple onload events conflicting, what you can do is first add the below function to the very end of sniffer.js. This function lets you assign a function to the BODY onload event without having it cancel out/ conflict with the next function that does the same:


function dotask(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}

So lets say initializePage() is the function you wish to assign to the BODY. You would call it this way instead:


dotask(window, function(){initializePage()}, "load")

dmelosi
11-26-2007, 12:20 AM
We have it working, thank you for your help.