Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 元刷新重定向到顶部框架_Javascript_Html_Redirect_Refresh_Meta Tags - Fatal编程技术网

Javascript 元刷新重定向到顶部框架

Javascript 元刷新重定向到顶部框架,javascript,html,redirect,refresh,meta-tags,Javascript,Html,Redirect,Refresh,Meta Tags,我有以下代码: <html> <head> <title>title of this stuff</title> <script language="JavaScript"> if (top != self) top.document.title = document.title; </script> <meta http-equiv="refresh" content="2; URL=javascrip

我有以下代码:

<html>
<head>
<title>title of this stuff</title>
<script language="JavaScript"> 
  if (top != self) top.document.title = document.title;
</script>
<meta http-equiv="refresh" content="2;     URL=javascript:window.open('certainpage.html','_top');">
</head>
<body>
Body of this page
</body>
</html>

这东西的名字
如果(top!=self)top.document.title=document.title;
本页正文
这不管用。 我在谷歌上搜索了一下,得出的结论都是一样的:这应该行得通。 但事实并非如此。有人能帮我解释一下为什么这个页面不是: 1.只要有javascript就可以刷新(是的,我的浏览器中启用了js) 2.刷新到顶部框架中的新页面


任何帮助都将不胜感激

Javascript在这样的刷新元标记中不起作用

在使用javascript时,请保持如下简单:

<script type="text/javascript">
    window.top.location = 'http://domain.tld/whatever/';
</script>

window.top.location文件http://domain.tld/whatever/';
但也有更好(因为更聪明)的方法。这不需要为每个页面硬编码URL。它检查页面是否位于最顶端,如果不是,则将页面的URL调用到最顶端:


if(window.top.location!=window.location)
{
window.top.location.href=window.location.href;
}
如果您希望完全避免使用javascript(有些用户会禁用javascript),还有一种更简单的方法。将以下内容添加到标题部分,该页面上的所有链接将打开“最顶端”:



你所要做的就是从这三个选项中选择一个。所有这些都会让你很顺利。

可能重复@Billy Moat:是的。我在a帧中运行一个脚本,而B帧显示了完成之前的进度(带有元刷新)。然后它应该更改元刷新,以便刷新到父帧。@Diodeus:“可能重复”。。有趣的不过,感谢您的回复,因为您链接到的页面上的window.location javascript(变成window.top.location)成功了!(必须加入一些脚本,使其仅在满足条件时发生)
<script type="text/javascript">
    if(window.top.location != window.location) 
    {
        window.top.location.href = window.location.href; 
    }
</script>
<base target="_top">