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 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    window.onblur not working in IE

    I need to add a feature to my web app where when a user tries to click on another application, it will trigger a form submit (this is an online testing system). So, I'm using the jscript window.onblur event to accomplish this. In FireFox, it works very well, however, in IE, it does not (no surprises there). Here is my code:

    <script type="text/javascript">
    window.onblur = blurText;
    function blurText() {
    // remove the event to stop an infinite loop!
    window.onblur = '';
    alert("It's blured");
    //document.f.submit();
    }
    </script>


    As you can see, I've commented out the actual submit line because I'm testing. In IE7, the window (it's a pop-up window) comes up normally, but when I simply click on the page anywhere, the onBlur is triggered. Does anyone know what might be causing this, and if there is a solution to it? Or, even an alternate way to do what I need?

    Thanks,
    Jesse

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    127.0.0.1
    Posts
    348
    Thanks
    26
    Thanked 40 Times in 39 Posts
    works in IE 6.
    Blog Charity:Water
    WhatisWrongWith.me/tagnu - Send me anonymous feedback.

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Doesn't in IE7, at least not on my machine.

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Works fine on IE7 and FF. Could you give us a link.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    New Coder
    Join Date
    Oct 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sure. Go to:

    http://www.castleberryweb.com/dlg/test/dlg/

    Log in with the user name 1234 and password qt

    Click the Select link beside the "FINANCIAL MATH..." test. That should load the test into a pop-up window.

    Now, the window should have focus, right? Now, just click anywhere on the page. You'll get a message, "It's blurred" But, it's not blurred, by clicking on the page, if anything, I'm just focusing back onto the page which should already have focus??

    Thanks,
    Jesse

  • #6
    New Coder
    Join Date
    Oct 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So, no one has any suggestions?

    Thanks,
    Jesse

  • #7
    New Coder
    Join Date
    Oct 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here's a little piece of information. I went back to basics, and started with a plain page, nothing on it at all. standard html tags, no doctype tag at the top or anything. window.onblur worked perfectly in both IE and FireFox. Then, I started adding elements. on my second try, I duplicated the problem. If I include a DOCTYPE declaration, then the onBlur fails the way I describe above. Take DOCTYPE out, and it works just fine.

    I really want my sites to be standard and correct, however, as usual, IE is not standards compliant. Does anyone have a suggestion for a workaround, or do I have to leave this page without a DOCTYPE declaration?

    Thanks,
    Jesse

  • #8
    New Coder
    Join Date
    Oct 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I believe I found a solution. Browsing around, I found a page, http://odondo.wordpress.com/category/computers/ that admitted that onBlur is not reliable, especially in IE. IE has it's own functions for this (of course), which tend to work better. So, I've changed my code to work like this:

    <script type="text/javascript">
    var isIE = (navigator.appName == "Microsoft Internet Explorer");
    var hasFocus = true;
    var active_element;

    function setFocusEvents() {
    active_element = document.activeElement;
    if (isIE) {
    document.onfocusout = function() { onWindowBlur(); }
    document.onfocusin = function() { onWindowFocus(); }
    } else {
    window.onblur = function() { onWindowBlur(); }
    window.onfocus = function() { onWindowFocus() }
    }
    }

    function onWindowFocus() {
    hasFocus = true;
    }

    function onWindowBlur() {
    if (active_element != document.activeElement) {
    active_element = document.activeElement;
    return;
    }
    hasFocus = false;
    document.f.submit();
    }
    </script>

    And, so far, it seems to be working. Just thought I'd share that.

    Thanks,
    Jesse


  •  

    Posting Permissions

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