Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    The wild blue yonder
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    drop-down menu script only works in IE

    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!
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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
    Code:
    var cDivs = document.all.tags("DIV");
    to this
    Code:
    var cDivs = document.all ? document.all.tags("DIV") : document.getElementsByTagName("div");
    and let us know how that all helps.

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    The wild blue yonder
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    The wild blue yonder
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, man.

    I changed this:
    Code:
    var cDivs = document.all.tags("DIV");
    to this:
    Code:
    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:
    Code:
    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:
    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:
    Code:
    function functionName (e) {
        if (!e) e = window.event;
    I'm confused. Thanks!

    Chris

  • #5
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    refer to these pages for documentation:

    MSDN DHTML Ref

    Mozilla DOM Events Ref

    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.

    Code:
    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()
    	}
    }

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    The wild blue yonder
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It's still in the new code because you probably want the script to work in ie, don't you?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Location
    The wild blue yonder
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I do. So the event.window doesn't PREVENT it working in other browsers, then? Ok, that makes sense.

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #10
    Regular Coder
    Join Date
    Oct 2003
    Location
    The wild blue yonder
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •