Html 为什么 Chrome 不使用元刷新重定向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22551976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does Chrome not redirect using meta refresh
提问by jeph perro
An application that I work with has a PL/SQL package that creates a page and uses a function to create META tags.
我使用的一个应用程序有一个 PL/SQL 包,它创建一个页面并使用一个函数来创建 META 标记。
It creates a webpage with a META tag exactly like this :
它创建了一个带有 META 标签的网页,如下所示:
<META HTTP-EQUIV="Refresh" NAME="Refresh" CONTENT="1; URL=PaymentSubmit.html">
The problem is that Chrome does not like the NAME="Refresh" attribute. It does not redirect the page, although it does redirect properly in IE and Firefox
问题是 Chrome 不喜欢 NAME="Refresh" 属性。它不会重定向页面,尽管它确实在 IE 和 Firefox 中正确重定向
If I remove the NAME attribute, so that it looks like this it works in all browsers :
如果我删除 NAME 属性,使它看起来像这样,它可以在所有浏览器中运行:
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=PaymentSubmit.html">
What's going on here? I can't find a W3C standard for META redirect, so does every browser make up it's own rules ? I'm not sure if it ever worked in Chrome, but since I never heard any bug reports I assume it used to work in Chrome.
这里发生了什么?我找不到用于 META 重定向的 W3C 标准,所以每个浏览器都有自己的规则吗?我不确定它是否曾在 Chrome 中工作过,但由于我从未听说过任何错误报告,因此我认为它曾经在 Chrome 中工作过。
Anyone have a similar problem ?
有人有类似的问题吗?
Thanks
谢谢
采纳答案by tjati
If you check the w3c wikiyou can find the following quote:
如果您查看w3c wiki,您可以找到以下引用:
Exactly one of the name, http-equiv, and charset attributes must be specified.
必须指定 name、http-equiv 和 charset 属性之一。
It mean's it is not valid html that both - name
and http-equiv
attributes are set.
这意味着 -name
和http-equiv
属性都设置为无效的html 。
Read this W3C's HTML and XHTML Techniques test on meta refresh:
阅读有关元刷新的 W3C 的 HTML 和 XHTML 技术测试:
Find all meta elements in the document. For each meta element, check if it contains the attribute http-equiv with value "refresh" (case-insensitive) and the content attribute with a number greater than 0 followed by ;'URL=anyURL' (where anyURL stands for the URI that should replace the current page).
查找文档中的所有元元素。对于每个元元素,检查它是否包含值为“refresh”(不区分大小写)的属性 http-equiv 和大于 0 的数字后跟 ;'URL=anyURL'(其中 anyURL 代表该 URI 的 URI)的内容属性应该替换当前页面)。
The behavouir of the other browsers is not wrong, but chrome is more strict.
其他浏览器的行为没有错,但chrome更严格。
More detailsabout the correct behavouir - and the valid reference - are available at http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv-refresh
有关正确行为和有效参考的更多详细信息,请访问http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv-refresh
回答by Amit Joki
As far as browser support:
至于浏览器支持:
The support for <meta>
refresh is there even in IE6
<meta>
即使在 IE6 中也支持刷新
The syntax to be used is:
要使用的语法是:
Place inside <head>
to refresh page after 5 seconds:
放置在里面<head>
5 秒后刷新页面:
<meta http-equiv="refresh" content="5">
Redirect to http://example.com/after 5 seconds:
5 秒后重定向到http://example.com/:
<meta http-equiv="refresh" content="5; url=http://example.com/">
Redirect to http://example.com/immediately:
立即重定向到http://example.com/:
<meta http-equiv="refresh" content="0; url=http://example.com/">
If you plan to support javascript disablers (Which I don't think you should do:)
如果您打算支持 javascript 禁用程序(我认为您不应该这样做:)
Do this:<noscript><meta http-equiv="refresh" content="0; url=url here"></noscript>
做这个:<noscript><meta http-equiv="refresh" content="0; url=url here"></noscript>
It is not a part of HTTP standard.
它不是 HTTP 标准的一部分。
However, there are alternatives:
但是,还有其他选择:
For refreshing the page after 5 seconds, do the below:
要在 5 秒后刷新页面,请执行以下操作:
<body onload="javascript:setTimeout(function(){ location.reload(); },5000);">
If you want to redirect after 5 seconds, then do the below:
如果您想在 5 秒后重定向,请执行以下操作:
<body onload="javascript:setTimeout(function(){ window.location = 'http://example.com';},5000);">
If you want to redirect immediately:
如果您想立即重定向:
<body onload="javascript:window.location='http://example.com'">
But there isn't any alternative for javascript disablers (yippee!!)
但是对于 javascript禁用程序(yippee !!)没有任何替代方案
Conclusion:
结论:
So, my suggestion, would be to use my javascript alternatives, because they are notgoing to be replaced.
所以,我的建议是使用我的 javascript 替代品,因为它们不会被替换。
But <meta>
refresh tag may be discontinued in the coming years.
但<meta>
刷新标签可能会在未来几年停止使用。
More reading : http://en.wikipedia.org/wiki/Meta_refresh
回答by Jean-Paul
For the <META
tags, Microsoft has published specific guidelines:
对于<META
标签,微软已经发布了具体的指导方针:
Specifically, for the <meta http-equiv="refresh">
element, Microsoft states the following:
具体来说,对于该<meta http-equiv="refresh">
元素,Microsoft 声明如下:
A page redirect should provide both a message with the new page location and sufficient time for users to read the message. A page redirect with a time-out period of less than five secondsmay result in a lower search-engine ranking.
To redirect a page, consider using an HTTP redirect instead. An HTTP redirect is more likely to transfer the authority of the old page to the new page.
页面重定向应提供带有新页面位置的消息和足够的时间供用户阅读消息。超时时间少于五秒的页面重定向可能会导致搜索引擎排名较低。
要重定向页面,请考虑改用 HTTP 重定向。HTTP 重定向更有可能将旧页面的权限转移到新页面。
Personally, instead of a <meta
refresh tag, I would recommend you use a 301 Redirect. In PHP you could do, for example, the following:
就个人而言,<meta
我建议您使用301 Redirect而不是刷新标签。例如,在 PHP 中,您可以执行以下操作:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.yourdomain.com/newpage");
?>
This method is better than the <meta
refresh because usually a 301 redirect includes the address to which the resource has been moved. Web browsers will typically follow 301 redirects to the new location automatically, without the need for user action.
这种方法比<meta
刷新更好,因为通常 301 重定向包括资源已移动到的地址。Web 浏览器通常会自动跟随 301 重定向到新位置,而无需用户操作。
According to somedefinitions of 301 Redirect
, it would even preserve old positions:
根据 的某些定义301 Redirect
,它甚至会保留旧位置:
A 301 redirect should be used whenever a website is moved to a new domain name (URL) so that search engines will quickly change their indeces and, in theory, preserve the search engine rankings that the site had at the previous domain.
每当将网站移至新域名 (URL) 时,都应使用 301 重定向,以便搜索引擎快速更改其索引,并在理论上保留该站点在前一个域中的搜索引擎排名。
All this is in line with the fact that many shady websites use <meta
refresh to open unwanted websites (spam/ advertisements etc.). Hence I would conclude that the refresh meta tag should notbe used.
所有这些都与许多可疑网站使用<meta
刷新打开不需要的网站(垃圾邮件/广告等)的事实相符。因此,我可以得出结论,刷新元标记应不被使用。
For the other meta tags, please read the following: 18 meta tags every webpage should have.
对于其他元标记,请阅读以下内容:每个网页都应该有 18 个元标记。
Keep in mind that not all meta tags are of crucial importance; for example, Google says it does not use the keywords meta tag in web ranking.
请记住,并非所有元标记都至关重要;例如,谷歌表示它不会在网络排名中使用关键字元标记。
But remember: it is Better to have, and not need, than to need, and not have.
但请记住:拥有但不需要比需要但没有更好。
Just don't use the <META refresh
;)
只是不要使用<META refresh
;)