How do I disable body.blur() in IE8?

2019-07-03 05:34发布

问题:

I work on an enterprise web application that runs in IE8. It appears blur() is being called on the body causing the IE window to be sent to the background. Unfortunately this code is in a portion of the application that is controlled by the vendor.

Is there any possible way to prevent blur() from being called on the body without modifying the code that is actually calling body.blur()?

Since this is an enterprise application, solutions outside of changes in the application itself are acceptable; Such as changes to IE8 settings, registry, etc.

回答1:

You should be able to hard code blur to a dummy method. If you can get in before it is called, just call body.blur = function() {}; (assuming body is pointing to your DOM body element).



回答2:

Using jQuery you could simply block the event :

$('body').blur(function(e) { e.preventDefault(); });


回答3:

If using Firefox is an option, i have two answers where i propose replacing the function using Greasemonkey.

  1. Using javascript to create a keylistener hotkey for facebook page "like"
  2. Greasemonkey script to replace jQuery plugin function?

If you have to use IE, you might need to change the page itself.
(I know there is Trixie and IE7pro for IE, but never used).



回答4:

I had an issue when using javaScript editor:CLEditor, if I use jQuery blur() method on it, the IE window goes to the background. CLEditor has it's iframe which has its own body. When you extract that body and use body.blur(), IE browser will go to the background.

Other browsers are not showing that behavior, so it is better to use FF, or Chrome if you are experiencing this.

If you remove body.blur(), probably you would have less problems with IE than you have now, but still you could experience some minor bugs (something is not loosing focus at certain point), but I suppose you could live with it. However if blur() event is enriched with some logic, it could be problem - then find its definition and move logic to some other event that is started with the browser (onload, or ready).



回答5:

document.body.blur=function(){document.body.focus()}