【问题标题】:Page with iframe inactivity redirection具有 iframe 不活动重定向的页面
【发布时间】: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


【解决方案1】:

您已将 iframe 设置为 100% 宽度和 800 像素高度。这几乎是您的所有网页。 iframe 旨在将其他网页的响应部分插入页面。在您的代码中,整个页面看起来都是 iframe。所以你要问自己,如果 iframe 几乎是整个页面,为什么还需要 iframe?为什么不直接链接到页面?

基本上,“母页”不会检测 iframe 中的移动和活动,因为它超出了它的控制范围,因此会执行您编写的脚本。唯一发生的活动是在 iframe 中链接到的网页上。 尽量避免使用 iframe。

【讨论】:

  • 我需要我的 Dock 仍然存在于链接页面中,但我无法控制 iframe 中的页面。无论如何感谢您的帮助!还不能投票,但你是一个帮助!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-22
  • 2011-01-06
  • 1970-01-01
  • 2015-03-11
  • 1970-01-01
  • 1970-01-01
  • 2013-03-12
相关资源
最近更新 更多