window.onblur事件在使用IE8时也会触发window.onfocus事件 [英] window.onblur event also triggers window.onfocus event when using IE8

查看:201
本文介绍了window.onblur事件在使用IE8时也会触发window.onfocus事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个事件都在onblur事件中被解雇。

Both the events are getting fired at the time onblur event.

<%@ 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>


推荐答案

最后它解决了。感谢您的帮助!

Finally it got solved. Thank you for all the help!

$(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');
        }

    }

这篇关于window.onblur事件在使用IE8时也会触发window.onfocus事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆