元刷新重定向到顶部框架 [英] meta refresh redirect to top frame

查看:92
本文介绍了元刷新重定向到顶部框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<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>

这不起作用。
我用Google搜索并在各处得出相同的结论:这应该有效。
但它没有。任何人都可以帮我解释为什么这个页面不是:
1.只要我在那里有javascript就可以刷新(是的,在我的浏览器中启用了js)
2.刷新到新页面在顶部框架

and this doesn't work. I've googled for this and come to the same conclusion everywhere: this should work. But it doesn't. Can anyone help me out why this page isn't: 1. refreshing as long as I have the javascript in there (and yes, js is enabled in my browser) 2. refreshing to the new page in the top frame

任何帮助将不胜感激!

推荐答案

Javascript无法在刷新元标记中使用。

Javascript won't work in the refresh meta tag like that.

正如您正在使用javascript一样,请保持简单,如下所示:

As you're using javascript anyway, keep it simple like this:

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

但也有更好(因为更聪明)的方式。这不要求您对每个页面的URL进行硬编码。它检查页面是否位于最顶层,如果不是,则调用页面的 top 的URL:

But there's also a better (because smarter) way to do it. This doesn't require you to hard-code the URL for each page. It checks if the page is topmost and if not, if calls the page's URL to the top:

<script type="text/javascript">
    if(window.top.location != window.location) 
    {
        window.top.location.href = window.location.href; 
    }
</script>

如果您希望完全避免使用javascript(某些用户将禁用),那么还有这是一种更简单的方法。将以下内容添加到 head 部分,该页面上的所有链接都将打开最顶层:

And if you would prefer to completely avoid using javascript (which some users will have disabled), there's also an even simpler way to do it. Add the following to your head section and all links on that page will open "topmost":

<base target="_top">

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

All you have to do is to choose one of these three options. All of them should get you going just fine.

这篇关于元刷新重定向到顶部框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆