There may be a slight difference in the conditions triggered by different browsers, and today we say that the focus and blur events of the IFRAME in the Firefox browser will trigger an invalid problem.
Solution:
1: Use Contentwindow, directly using jquery blur and focus, if you use native, add a browser to judge then Attachevent and AddEventListener on the line
The code is as follows |
Copy Code |
$ ($ (' #frame ') [0].contentwindow). blur (function () {}) $ ($ (' #frame ') [0].contentwindow]. focus (function () {}) |
2:settimeout Solve It
The code is as follows |
Copy Code |
$ (' #target '). Focusout (function () { settimeout (function () { $ (this). focus (); }, 0); }); |
Why is there such a problem with FF? In fact, in the HTML standard IFRAME is not these events, but IE to add. In Firefox, you can deal with this kind of event by Contentwindow this way.
Once again the depth of Google, found a foreigner wrote a very good code:
code is as follows |
copy code |
<script> Function Setit () { if ( document.all) { document.getElementById ("MyFrame"). Attachevent ("onblur", Dothis); }else{ document.getElementById ("MyFrame"). Contentwindow.addeventlistener ("Blur", Dothis,false); } } Function dothis () { Alert ("Blurred"); } </script> <body onload= "Setit ()" > <iframe width= "height=" 144 "id=" MyFrame "></iframe> <input/> |
Try it really can trigger directly, the effect is the same as under IE. Back to analyze the code, found that the Firefox central Plains to the incident on the iframe hanging to the Contentwindow in the IFRAME, and the true connection in the HTML element to write event properties, IE may connect the events on the IFRAME to the Contentwindow, but Firefox is not the case, or each is different. The problem with this is that Firefox wants to give the IFRAME an extra script to add to the event.