Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Chrome not redirect using meta refresh

An application that I work with has a PL/SQL package that creates a page and uses a function to create META tags.

It creates a webpage with a META tag exactly like this :

 <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

If I remove the NAME attribute, so that it looks like this it works in all browsers :

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

Anyone have a similar problem ?

Thanks

like image 474
jeph perro Avatar asked Mar 21 '14 06:03

jeph perro


People also ask

How do I fix meta refresh redirect?

How to fix this issue. Delete the tag <meta http-equiv=”refresh” content=”10″> and apply redirect 301 for forwarding to the right page. Check inner links, they must lead to the page a user is forwarded to from the current one. Page A link to -> bad Page -> 301 redirect to ->PageB.

What is meta refresh in Chrome?

Meta refresh is a method of instructing a web browser to automatically refresh the current web page or frame after a given time interval, using an HTML meta element with the http-equiv parameter set to " refresh " and a content parameter giving the time interval in seconds.

Is meta refresh deprecated?

The use of Meta Refresh Redirect is deprecated or in other words, disapproved by W3C(World Wide Web Consortium), since it is a non-standard procedure of redirection, it disorients users, and it can also disrupt a browser's history of visited pages.

How do I redirect meta?

To use a META Tag to redirect your site is quite easy. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The following is an example of redirecting current page to another page after 2 seconds.


3 Answers

If you check the w3c wiki you can find the following quote:

Exactly one of the name, http-equiv, and charset attributes must be specified.

It mean's it is not valid html that both - name and http-equiv attributes are set.

Read this W3C's HTML and XHTML Techniques test on meta refresh:

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

The behavouir of the other browsers is not wrong, but chrome is more strict.

More details about the correct behavouir - and the valid reference - are available at http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv-refresh

like image 101
tjati Avatar answered Oct 18 '22 22:10

tjati


As far as browser support:

The support for <meta> refresh is there even in IE6

The syntax to be used is:

Place inside <head> to refresh page after 5 seconds:

<meta http-equiv="refresh" content="5">

Redirect to http://example.com/ after 5 seconds:

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

Redirect to http://example.com/ immediately:

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

Do this:<noscript><meta http-equiv="refresh" content="0; url=url here"></noscript>

It is not a part of HTTP standard.

However, there are alternatives:

For refreshing the page after 5 seconds, do the below:

<body onload="javascript:setTimeout(function(){ location.reload(); },5000);">

If you want to redirect after 5 seconds, then do the below:

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

Conclusion:

So, my suggestion, would be to use my javascript alternatives, because they are not going to be replaced.

But <meta> refresh tag may be discontinued in the coming years.

More reading : http://en.wikipedia.org/wiki/Meta_refresh

like image 33
Amit Joki Avatar answered Oct 18 '22 20:10

Amit Joki


For the <META tags, Microsoft has published specific guidelines:

Page and site guidelines for SEO

Specifically, for the <meta http-equiv="refresh"> element, Microsoft states the following:

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

Personally, instead of a <meta refresh tag, I would recommend you use a 301 Redirect. In PHP you could do, for example, the following:

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

According to some definitions of 301 Redirect, it would even preserve old positions:

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.

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 not be used.

For the other meta tags, please read the following: 18 meta tags every webpage should have.

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

like image 2
Jean-Paul Avatar answered Oct 18 '22 22:10

Jean-Paul