...

drop-down menu script only works in IE

cjwsb
10-30-2003, 02:23 AM
Hi all,

A friend wrote a javascript for me that I use at http://www.bartlett-family.net/sokhan . Unfortunately, it only works in IE. I need it to work in NS and Opera. I know NOTHING about javascript, and he does not know how to do it for anything other than IE. Can someone please tell me how to make the attached script function in NS and Opera? Sorry if it's a dumb question, but I just don't know javascript at all... Thanks a million!

Chris

PS. I posted this same message in the previous forum, but it then dawned on me that it probably belongs here. My bad, sorry!

Choopernickel
10-30-2003, 01:41 PM
There's a load of IE-only stuff in there; the most obvious is all the window.event stuff. In all of the functions which refer to window.event, change the opening of the function to this:
function functionName (e) {
if (!e) e = window.event;
and change all the function-internal references to window.event to refer instead to e.
You may wish to implement the DOM2Event class available at http://www.dithered.com/ - it's made my life with event handlers much, much easier to deal with.

Also, there's a line that refers to document.all - which is a MAJOR IE-only type of thing. Change this var cDivs = document.all.tags("DIV"); to this var cDivs = document.all ? document.all.tags("DIV") : document.getElementsByTagName("div"); and let us know how that all helps.

cjwsb
10-30-2003, 01:48 PM
Thanks bro!

Lemme start with all of that and see what happens. Could you please check back later? I'm certain I'll need more help! I appreciate it!

Chris

cjwsb
10-30-2003, 03:10 PM
Ok, man.

I changed this:
var cDivs = document.all.tags("DIV");
to this:
var cDivs = document.all ? document.all.tags("DIV") : document.getElementsByTagName("div");
That has helped. Now, in Opera, the drop-down menus at least show up when a link is clicked. If I click a link in the drop-down menu, however, I egt the following havascript error message in Opera:

Event thread: onclick
Error:
name: TypeError
message: Statement on line 278: Expression evaluated to null or undefined and is not convertible to Object: sURL
Backtrace:
Line 278 of linked script http://www.bartlett-family.net/sokhan/wcd00074.js
sFrameURL = sURL.substring(0, sURL.indexOf("#"));
Line 307 of linked script http://www.bartlett-family.net/sokhan/wcd00074.js
sURL = hackURL(window.event.srcElement.myURL);
At unknown location
{event handler trampoline}


Regarding the "window.event stuff, I'm not sure what you mean exactly. Here's a snippet of code:

function menuTitle_mouseover() {

var eSrc = window.event.srcElement

if (eSrc.className != "clsMenuTitleDown") {

eSrc.className = "clsMenuTitleOver"

}

if (sMenuTitleDownID != "" && eSrc.className == "clsMenuTitleOver") {
menuTitle_click()

}

}

What exactly would I change that to? There seems to be more there than simply:

function functionName (e) {
if (!e) e = window.event;

I'm confused. Thanks!

Chris

Choopernickel
10-30-2003, 06:26 PM
refer to these pages for documentation:

MSDN DHTML Ref (http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_event.asp)

Mozilla DOM Events Ref (http://www.mozilla.org/docs/dom/domref/dom_event_ref.html#998197)

Anyway, yes, it can be more difficult than just swapping over window.event or arguments["e"], as in the snippet you posted. Check this out.

function menuTitle_mouseover(e) {
var eSrc;
if (!e) {
eSrc = window.event.srcElement;
} else {
eSrc = e.target;
}
if (eSrc.className != "clsMenuTitleDown") {
eSrc.className = "clsMenuTitleOver"
}
if (sMenuTitleDownID != "" && eSrc.className == "clsMenuTitleOver") {
menuTitle_click()
}
}

cjwsb
10-30-2003, 06:36 PM
Ok, I changed that. No noticeable difference, but then again, I haven't changed anything else. One thing I don't understand. You said the "window.event" was bad IE stuff. Why is it still in the new code, then? I don't get it. Thanks!

Chris

liorean
10-30-2003, 06:45 PM
It's still in the new code because you probably want the script to work in ie, don't you?

cjwsb
10-30-2003, 06:56 PM
Yes, I do. So the event.window doesn't PREVENT it working in other browsers, then? Ok, that makes sense.

liorean
10-30-2003, 07:04 PM
It's simply an example of microsoft doing things in a way different from how everyone else does it, and does not correct their way because of - as I think - what must be pure pride. Microsoft could have joined the crowd and still allowed their way in paralell, but they didn't.

cjwsb
10-30-2003, 07:22 PM
Yeah, MS definitely sux. Would you be willing to help me out with this script? I'd really like to get it working completely in NS and Opera. I'm just completely lost here, lol. :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum