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(newthis.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 iinthis.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("iFrame"),function() { alert('a click') })
用其他容器滚动来替代iframe的滚动,把iframe的scrolling设置为no<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script type="text/javascript" src="jquery-1.3.1.js"></script>
<script type="text/javascript">
$(function() {
var frame = $("#frame")
var win = frame[0].contentWindow
$(win).load(function() {
var dom = win.document
$(dom.body).css({margin:'0',padding:'0',border:'0',width:'100%',height:'100%'})
.html(
'<div id="layer" style="width:100%height:100%overflow:autobackground:red">' +
'<div style="width:1000pxheight:1000px">scroll' +
'</div>' +
'</div>'
)
$("#layer", dom.body).scroll(function() {
alert('invoke')
})
})
})
</script>
</head>
<body>
<iframe id="frame" frameborder="2" scrolling="no" src="about:blank" style="width:300pxheight:200px"></iframe>
</body>
</html>
可以通过windows自定义的reload方法实现的,之后在src后面增加个onchange事件,之后调用setInterval方法即可:<script type="text/javascript">
setInterval(function () {
window.location.reload()
}, 1000) // 单位: 毫秒, 1000 = 1 秒
</script>
之后即可一秒后刷新整个页面。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)