Meta refresh


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. It is also possible to instruct the browser to fetch a different URL when the page is refreshed, by including the alternative URL in the content parameter. By setting the refresh time interval to zero, meta refresh can be used as a method of URL redirection.

History

This feature was originally introduced by Netscape Navigator 1.1, in a form of HTTP header and corresponding HTML meta HTTP-equivalent element, which allows document author to signal client to automatically reload the document or change to a specified URL after a specified timeout. It is the earliest polling mechanism available for the web, to let user see the latest update in a frequently-changing webpage, such as ones displaying stock price or weather forecast.
While this feature has not ever been standardized, it is supported by default in almost all later web browsers.

Usability

Use of meta refresh is discouraged by the World Wide Web Consortium, since unexpected refresh can disorient users. Meta refresh also impairs the web browser's "back" button in some browsers, although most modern browsers compensate for this.
There are legitimate uses of meta-refresh, such as providing updates to dynamic web pages or implementing site controlled navigation of a website without JavaScript. Many large websites use it to refresh news or status updates, especially when dependencies on JavaScript and redirect headers are unwanted.

Examples

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

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



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


Drawbacks

Meta refresh tags have some drawbacks:
Meta refresh uses the http-equiv meta tag to emulate the Refresh HTTP header, and as such can also be sent as a header by an HTTP web server, although Refresh is not part of the HTTP standard.
Alternatives exist for both uses of meta refresh.

For redirection

An alternative is to send an HTTP redirection status code, such as HTTP 301 or 302. It is the preferred way to redirect a user agent to a different page. This can be achieved by a special rule in the Web server or by means of a simple script on the Web server.
JavaScript is another alternative, but not recommended, because users might have disabled JavaScript in their browsers.
The simplest way of JavaScript redirect using the onload property of the body tag:



For refresh

An alternative method is to provide an interaction device, such as a button, to let the user choose when to refresh the content. Another option is using a technique such as Ajax to update the Web site without the need for a complete page refresh, but this would also require that the user enable JavaScript in their browser.