Html 元刷新不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/522353/
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
Meta-refresh doesn't work?
提问by GBa
I have a page using something along the lines of
我有一个页面使用类似的东西
<meta http-equiv="refresh" content="0;url=http://example.com/" />
but for certain users on a certain workstation this doesn't work. The is in IE. Is there something wrong with cookies or a setting somewhere which would cause this to fail? I never heard of such a thing.
但是对于某个工作站上的某些用户,这不起作用。在 IE 中。cookie 或某处的设置是否有问题会导致此失败?我从来没有听说过这样的事情。
回答by
The problem is that when IE sees this:
问题是当IE看到这个:
<meta http-equiv="refresh" content="0;http://www.example.com" />
it expects the contents attribute to contain a number. The only time IE will check for a URL is if the content attribute contains "URL=" so the redirect that is most usable in all browsers is this:
它期望内容属性包含一个数字。IE 将检查 URL 的唯一时间是内容属性是否包含“URL=”,因此在所有浏览器中最有用的重定向是这样的:
<meta http-equiv="refresh" content="0;URL=http://www.example.com" />
The above example would redirect immdetiately but if you changed the 0 for another number it would wait that many seconds. Hope this all makes sense, it should work just fine but I still think my first idea was the better one.
上面的例子会立即重定向,但如果你将 0 更改为另一个数字,它会等待那么多秒。希望这一切都有意义,它应该可以正常工作,但我仍然认为我的第一个想法是更好的。
回答by Austin
There is a security setting in internet explorer that does not allow meta tag refresh. It is under the Security tab, then choose Custom Level and the Meta Tag Refresh under Miscellaneous. If that is disabled, it would stop the meta refresh from working.
Internet Explorer 中的安全设置不允许元标记刷新。它位于安全选项卡下,然后选择自定义级别和杂项下的元标记刷新。如果禁用它,它将停止元刷新工作。
Aside from being able to disable it selectively, it is automatically disabled if you set IE's security level to 'High' [observed in IE9].
除了能够有选择地禁用它之外,如果您将 IE 的安全级别设置为“高”[在 IE9 中观察到],它会自动禁用。
回答by Cal
is it a really old version of IE? if so, try:
它是一个真正的旧版本的 IE 吗?如果是这样,请尝试:
<meta http-equiv="refresh" content="0;url=http://example.com/"> </meta>
It needs a white space. HTML editor will complain, but just ignore it.
它需要一个空白区域。HTML 编辑器会抱怨,但请忽略它。
回答by Haluk
Check out this solution. It handles both javascript and meta-refresh at the same time: Meta-refresh and javascript
看看这个解决方案。它同时处理 javascript 和元刷新: Meta-refresh and javascript
回答by DevelopersDevelopersDevelopers
The META tag is not an empty tag and does not have a closing tag in HTML, only in XHTML. (If you are really are sending XHTML, it may not work right on older versions of IE anyway, there are only workarounds to send XHTML to older IE versions.)
META 标签不是空标签,在 HTML 中没有结束标签,只有在 XHTML 中才有。(如果您确实要发送 XHTML,则它可能无法在旧版本的 IE 上正常工作,只有将 XHTML 发送到旧 IE 版本的解决方法。)
Try:
尝试:
<meta http-equiv="refresh" content="0;url=http://example.com/">
W3 Schools META Tag Description
You might also try:
您也可以尝试:
- Checking the major and minor versions of IE. You can do this on the help->about menu option.
- IE has historically gotten all confused by filenames and MIMEtypes. Make sure that you are sending your HTML as an htm or html extension file, and that those filetypes are set up on your server to send text/html mimetype.
- Make sure your server isn't sending a conflicting meta refresh http header.
- 检查 IE 的主要和次要版本。您可以在帮助->关于菜单选项上执行此操作。
- IE 历来都被文件名和 MIME 类型弄糊涂了。确保您将 HTML 作为 htm 或 html 扩展文件发送,并且这些文件类型在您的服务器上设置为发送 text/html mimetype。
- 确保您的服务器没有发送冲突的元刷新 http 标头。
回答by Kosi2801
Just a wild guess: maybe there are some adblockers installed on those machines where the redirect does not work. Can't think of any other reason why this common technique works on some machines while it fails on others for you.
只是一个疯狂的猜测:也许在那些重定向不起作用的机器上安装了一些广告拦截器。想不出为什么这种常见技术在某些机器上有效而在其他机器上却对您无效的任何其他原因。
回答by Raptor
In case anyone tries to use meta refresh to redirect to new URLin Facebook applications ( either Page Tab app or IFRAME app ), the tag is disabled by Facebook somehow.
如果有人尝试使用元刷新重定向到Facebook 应用程序(页面选项卡应用程序或 IFRAME 应用程序)中的新 URL,Facebook 会以某种方式禁用该标签。
Workaround is:
解决方法是:
<script>
top.window.location = 'http://example.com';
</script>
Remember to target "top", as Facebook applications are in IFRAME.
请记住以“顶部”为目标,因为 Facebook 应用程序在 IFRAME 中。