Meta-refresh doesn't work?

2019-01-31 11:43发布

问题:

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.

回答1:

The problem is that when IE sees this:

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

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



回答2:

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.

Aside from being able to disable it selectively, it is automatically disabled if you set IE's security level to 'High' [observed in IE9].



回答3:

is it a really old version of IE? if so, try:

<meta http-equiv="refresh" content="0;url=http://example.com/"> </meta>

It needs a white space. HTML editor will complain, but just ignore it.



回答4:

Check out this solution. It handles both javascript and meta-refresh at the same time: Meta-refresh and javascript



回答5:

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

Try:

<meta http-equiv="refresh" content="0;url=http://example.com/">

W3 Schools META Tag Description

You might also try:

  1. Checking the major and minor versions of IE. You can do this on the help->about menu option.
  2. 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.
  3. Make sure your server isn't sending a conflicting meta refresh http header.


回答6:

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.



回答7:

In case anyone tries to use meta refresh to redirect to new URL in Facebook applications ( either Page Tab app or IFRAME app ), the tag is disabled by Facebook somehow.

Workaround is:

<script>
top.window.location = 'http://example.com';
</script>

Remember to target "top", as Facebook applications are in IFRAME.