SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist S7even's Avatar
    Join Date
    Jun 2002
    Posts
    481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Works in IE and Mozilla but not in NS

    Can you tell me why the following works in IE, Mozilla and Opera but not in NS? I don't care about NS4, I just need it to work in NS6+

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Mouse Over</title>
    <script language="JavaScript" type="text/javascript">
    function domouseover(e) {
    e = (e) ? e : (window.event) ? window.event : ""
    if (e) {
    var elem = (e.target) ? e.target : e.srcElement
    if (elem.className == "test") {
    y=elem.id+'r';
    document.getElementById(y).style.color = 'red';
    }
    }
    }
    function domouseout(e) {
    e = (e) ? e : (window.event) ? window.event : ""
    if (e) {
    var elem = (e.target) ? e.target : e.srcElement
    if (elem.className == "test") {
    y=elem.id+'r';
    document.getElementById(y).style.color = 'black';
    }
    }
    }
    document.onmouseover=domouseover;
    document.onmouseout=domouseout;
    </script>
    </head>
    <body>
    <div id="x1r">
    This should become red when you mouse over the link, but it doesn't in Netscape.
    </div>
    <a href="#" id="x1" class="test">Mouse over me</a>
    </body>
    </html>

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    e.currentTarget 
    Does that work ?

  3. #3
    SitePoint Evangelist S7even's Avatar
    Join Date
    Jun 2002
    Posts
    481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you mean to replace e.target with e.cuurentTarget, it doesn't work.

    Anthing else I can try?

  4. #4
    SitePoint Evangelist S7even's Avatar
    Join Date
    Jun 2002
    Posts
    481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i found out that for NS to work it needs:
    e.target.parentNode

    When i put that, IE and NS work, but not Mozilla
    How can I make all browsers work?

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Throw an if switch:
    Code:
    if (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) > 6) {
      //use e.target.parentNode
    } else {
      //use what you've been using.
    }
    Edit:

    Yes I know, it's browser detection, but I can't think of a better way right now

  6. #6
    SitePoint Evangelist S7even's Avatar
    Join Date
    Jun 2002
    Posts
    481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but that didn't help much since both NS7 and Mozilla (at least the one I have) have 'Netscape' as their appName and '5.0 (Windows; en-US)' as their appVersion ...

  7. #7
    SitePoint Evangelist S7even's Avatar
    Join Date
    Jun 2002
    Posts
    481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I found the answer:
    Code:
    function func(e) {
      e = (e) ? e : ((window.event) ? window.event : "")
      if (e) {
    	var elem
    	if (e.target) {
    	  elem = (e.target.nodeType == 3) ? e.target.parentNode : e.target
    	} else {
    	  elem = e.srcElement
    	}
    //code here
      }
    }

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice Took a copy myself for reference at a later date if that's okay ? Much kindness.


Bookmarks

Posting Permissions

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