我有一個包含iframe的頁面。如果用戶在x秒內沒有活動(沒有keydown和mousemove),我會在頁面重定向到主頁的地方放上代碼。我的問題是,代碼只能在母版中使用,但不會檢測iframe中的mousemove和keydown,因此無論活動如何,都會在iframe中每次都重定向。我試圖在iframe的onload事件中調用一個函數,但是這並不能工作。這裏是頁面的代碼:使用iframe不活動重定向的頁面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SAMPLE</title>
<link href="main.css" rel="stylesheet" type="text/css" media="screen" />
<script language="javascript">
function redirect()
{
var timer;
window.onload= document.onmousemove= document.onkeypress= function(){
clearTimeout(timer);
timer=setTimeout(function(){location= 'index.html'},3000);
}
}
</script>
</head>
<body bgcolor="blue" onLoad="redirect();">
<iframe src="http://tplink.teleperformanceusa.com" frameBorder="0" width="100%" height="800px" onLoad="redirect();"></iframe>
...
</body>
</html>
任何幫助,將不勝感激。謝謝!
不要使用iFrames,它們已經過時。 – Jonast92 2013-03-08 05:31:03
以什麼方式可以顯示我無法控制的頁面? – roncelajes 2013-03-08 05:49:53
@ Jonast92如果iframe已過時,應該使用什麼呢? – JJJ 2013-03-08 09:16:05