【发布时间】:2013-03-08 02:57:58
【问题描述】:
我有一个包含 iframe 的页面。我放置了一个代码,如果用户在 x 秒内不活动(没有 keydown 和 mousemove),页面将重定向到主页。我的问题是代码仅在母页中有效,但没有检测到 iframe 中的 mousemove 和 keydown,因此尽管有活动,但它每次都在 iframe 内重定向。我尝试在 iframe 的 onload 事件中调用一个函数,但这不起作用。这是页面的代码:
<!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>
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
不要使用 iFrame,它们已经过时了。
-
我可以通过什么方式显示我无法控制的页面?
-
@Jonast92 如果 iframe 已经过时,应该使用什么来代替?
-
或者,如果我无法控制它,有什么方法可以将我的 Dock 嵌入到重定向站点?
-
为什么不尝试这种情况下的 php 会话?
标签: javascript jquery html redirect iframe