SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    Maryland
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mozilla blur() problem

    Please take a look at this page:

    http://home.comcast.net/~delerious1/index10b.html

    There is javascript code that is executed when the page is loaded. The code
    calls the focus() method and then the blur() method on the first anchor in the
    box. In IE and Opera the code works. But in Mozilla, you can see the dotted
    line around the first anchor, so it's as if the blur() method is not working.

    Anyone know what's going on?

  2. #2
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A couple of things. Firstly, your style element should be in the <head>, not the <body>.

    On to the real problem:

    If I take the "break;" out, and add an alert(i) call inside the if statement, it becomes clear what's happening: only the very first call to focus() or blur() is actually doing anything. Subsequent calls in the same function are ignored. Since this happens to be the "focus" call on the first link, the page gets stuck like that.

    I've had a good dig in bugzilla, and I can't find any likely looking bugs. You might have found a new one

    This might be a "feature", intended to guard against nasty infinite recursion of onblur/onfocus events (which has been a problem in the past - there are several resolved crash bugs in there that describe this phenomenon)

    I have to ask, why are you doing all this focussing and blurring anyway?

    [thinks]

    Here we go: a quick-and-dirty hack that seems to fix things in mozilla by playing on its quirks. Change the fixbug function to this:
    Code:
    function fixbug() {
       var submenu = document.getElementById('submenu');
       for (var i=0; i<submenu.childNodes.length; i++) {
     	// check for an anchor, since some nodes are named '#text'
     	if (submenu.childNodes[i].nodeName.toUpperCase() == 'A') {
     	  submenu.childNodes[i].blur();
     	  submenu.childNodes[i].focus();
     	  submenu.childNodes[i].blur();
     	  break;
     	}
       }
     }
    Moz will only process the first blur() call - which does nothing. Any hypothetical Other Browser (TM) which is the intended recipient of all these focus/blur shenanigans will just have to do an extra step, and end up a little more confused than before

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    Maryland
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi blufive, thanks for the reply, your fix works!

    Hahaha, you must be wondering what the point of that focusing and blurring is...

    Well, it's to fix another bug in IE:
    http://www.sitepointforums.com/showthread.php?t=143927


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
  •