在页面中增加事件的监听很容易,但对于框架页中增加onclick就没有任何动作反应了,也是经过百度查询找到了解决办法。具体代码分享如下:
HTML页面中的iframe框架:
<iframe src="www.19jp.com.html" id="Frame_chajian" name="Frame_chajian" frameborder="0" scrolling="no" ></iframe>
JS代码:
<script> //框架iframe事件监听 var IframeOnClick = { resolution: 200, iframes: [], interval: null, Iframe: function() { this.element = arguments[0]; this.cb = arguments[1]; this.hasTracked = false; }, track: function(element, cb) { this.iframes.push(new this.Iframe(element, cb)); if (!this.interval) { var _this = this; this.interval = setInterval(function() { _this.checkClick(); }, this.resolution); } }, checkClick: function() { if (document.activeElement) { var activeElement = document.activeElement; for (var i in this.iframes) { if (activeElement === this.iframes[i].element) { // user is in this Iframe if (this.iframes[i].hasTracked == false) { this.iframes[i].cb.apply(window, []); this.iframes[i].hasTracked = true; } } else { this.iframes[i].hasTracked = false; } } } } }; IframeOnClick.track(document.getElementById("Frame_chajian"), function() { mdaima() }); //mdaima()为要执行的事件 </script>
以上就是iframe框架页增加onclick事件的监听方法的详细内容,更多关于iframe框架页增加onclick事件的监听方法的资料请关注九品源码其它相关文章!