Introduction to the problem of onblur failure after the src attribute of iframe is modified in Firefox browser

黄舟
Release: 2017-07-21 13:18:32
Original
1944 people have browsed it

Introduction to the problem of onblur failure after the src attribute of iframe is modified in Firefox browser

<span style="font-family:Microsoft YaHei;font-size:18px;">
<span style="background-color: rgb(255, 255, 255);">昨天写了一下 </span>
<a target=_blank href="http://blog.csdn.net/u012175246/article/details/44104783" target="_blank" style="background-color: rgb(255, 255, 255);">笔记</a> 
<span style="background-color: rgb(255, 255, 255);">,提到了火狐iframe的onblur事件失效的问题。(这是火狐固有的问题,见 </span>
<a target=_blank href="qq://txfile/#" style="background-color: rgb(255, 237, 196);"> 
<span style="background-color: rgb(255, 255, 255);"> 。)虽然笔记里的方法解决了失效的问题,但当我改变iframe的src属性值之后,onblur事件再次失效。</span>
</span>
Copy after login

I asked a question on the explosion stack, and after the experts answered it, the problem was finally solved.

The reason is that after changing the src attribute value of the iframe, the browser will refresh the content of the iframe, and the onblur event will fail at this time. The solution is to rebind the event every time the iframe is loaded. That is, add the onload attribute in the iframe. This attribute value corresponds to the function bound to the event.

<span style="font-size:14px;">
<iframe id="iframe" src="" scrolling="yes" style="display: none;width:500px;height:500px" src="" onblur="hide()" onload="seint()">
</iframe>
</span>
Copy after login


<span style="font-size:14px;"><script>
function seint(){
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  
		document.getElementById("iframe").contentWindow.addEventListener("blur",hide,false);  
   	}
}
</script></span>
Copy after login

The above is the detailed content of Introduction to the problem of onblur failure after the src attribute of iframe is modified in Firefox browser. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!