2012-06-07 1 views
1

onblur 이벤트가 발생할 때 두 이벤트가 모두 발생합니다.window.onblur 이벤트는 IE8을 사용할 때 window.onfocus 이벤트도 트리거합니다.

<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" 
Inherits="WebApplication1.WebForm1" Title="Untitled Page" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
    <script src="js/jquery-1.7.2.js" type="text/javascript"></script> 
    <script language="javascript" type="text/javascript"> 
     window.onfocus = function() { 
      $('#msg').html($('#msg').html() + '<br/> focus'); 
     }; 
     window.onblur = function() { 
      $('#msg').html($('#msg').html() + '<br/> Blur'); 
     }; 
    </script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
    <div id="msg"> 
    </div> 
</asp:Content> 
+0

문제를 복제하는 jsfiddle을 만들 수 있습니까? –

+0

_window_ 대신 _document.body_에 _focus_ 및 _blur_ 이벤트를 등록하십시오. –

+0

@AshBurlaczenko http://jsfiddle.net/e2XBt/ – AshokD

답변

4

마지막으로 해결되었습니다. 모든 도움을 주셔서 감사합니다!

$(window).bind("load", function() { 
     pageLoad(); 
    }); 

    var activeElement; 

    function pageLoad() { 
     activeElement = document.activeElement; 
     document.onfocusout = logWindow; 
    } 

    function logWindow() { 
     if (activeElement != document.activeElement) { 
      activeElement = document.activeElement; 
     } 
     else { 
      $('#msg').html($('#msg').html()+'<br/> Focus'); 
     } 

    } 
+0

이것은 무엇입니까? 설명 해주십시오. – dhinesh

+1

@dhinesh IE는 window.onblur 이벤트에 문제가 있습니다. 따라서 위의 해결 방법입니다. 창로드시 document.onfocusout 이벤트를 등록하고 문서를 activeElemnt로 설정합니다. http://msdn.microsoft.com/en-us/library/ie/ms536936%28v=vs.85%29.aspx 이 이벤트는 window.onblur의 경우와 다르지 않습니다. 컨트롤이 손실되면 포커스 문서의 onfocusout 이벤트가 시작됩니다. – AshokD

+0

+1 - Epic. $ (window) .blur가 ie8에서 실패했을 때 나를 위해 일했습니다. –

1
window.onblur = function() { 
     $('#msg').html($('#msg').html() + '<br/> Blur');  
     return false; 
}; 

이벤트가 나왔을 점점 될 수 있습니다.

+0

여전히 동일한 문제가 발생합니다. – AshokD

관련 문제