开发者

IE is randomly minimizing when a link is clicked

I have the bizarre problem. When I click on a link in IE7 the window minimizes. It seems to only be a subset of the links on the page. It also doesn't consistently happen with the same link and differs from computer to computer.

example link text:

<a hidefocus="on" href="#" tabindex="1"><span unselectable开发者_Python百科="on" id="extdd-102">Canadian Legislation</span></a>

Anyone seen this before or have any idea what might be causing it?


Finally figured it out. It was actually a custom JavaScript click handler that caused the problem.

My click handler was calling activeElement.blur(); on the current active element (so that events tied to blur fired when the elements were destroyed).

Problem is in IE, if you call blur on anything that isn't an INPUT, it minimizes the window.


I had the same issue on Internet Explorer 10.

  • Internet Explorer 10 tested behaviour:

This issue only happen when you invoke the blur() function on document.body element.

Issue can be reproduced simply executing

 document.body.blur() 
in your browser console.

  • Common scenario in which this issue happens:

document.activeElement.blur() function invocation is the most common scenario in which this issue occurs because after first invocation of document.activeElement.blur() the body element will become the activeElement and subsequent call to document.activeElement.blur() will invoke blur on body element.

  • Solution:

avoid document.body.blur() function invocation, if you have jquery you can introduce this simple logic

 $(yourObj).is('body') 

to check if your object is the body element, in order to avoid blur() function invocation on it


IE is buggy, so you can troubleshoot by removing "tabindex". If that doesn't work try removing "unelectable" then "hideonfocus". "Hideonfocus" sounds weird. Try removing that first. Do you have any third party programs or plugins that interact with IE? Does it work on a different computer?


This happened when I used the blur workaround to get the placeholder attribute to work on IE8. In the workaround I should call blur() which caused the browser to blur (minimize to tray). The solution is to use:

$.each($('[placeholder]'), function(i,item){ item.blur();});

which is only being specific what to call blur on.

The complete placeholder workaround is:

$('[placeholder]').focus(function() {
    var input = $(this);
    if (input.val() === input.attr('placeholder')) {
        input.val('');
        input.removeClass('placeholder');
    }
}).blur(function() {
    var input = $(this);
    if (input.val() === '' || input.val() == input.attr('placeholder')) {
        input.addClass('placeholder');
        input.val(input.attr('placeholder'));
    }
}).blur();

$(window).on('load', function () {
    if ( $('[placeholder]').length ){
    $.each($('[placeholder]'), function(i, item){item.blur();});
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜