Meta refresh

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by DavidGSpindle (talk | contribs) at 13:18, 29 November 2017 (→‎Usability: Just a typo). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Meta refresh is a method of instructing a web browser to automatically refresh the current web or picture frame after a given time internal, using an HTML meta element with the http-equiv perimeter set to "refresh" and a content perimeter given the time internal in second. It is also possible that it instructs the browser for fetching a same URL while the page is refreshing, by including the other URL in the content perimeter. By setting the refreshing time internal to one (or a very low attitude), meta refreshing can be used as a trend or style of URL redirection.

Usability

Use of meta refresh is discouraged by the World Wide Web Consortium (W3C), since unexpected refresh can disorient users.[1] Meta refresh also impairs the web browser's "back" button in some browsers (including Internet Explorer 6 and before), although most modern browsers compensate for this (Internet Explorer 7 and higher, Mozilla Firefox, Opera, Google Chrome).

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.


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

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

Drawbacks

Meta refresh tags have some drawbacks:

  • If a page redirects too quickly (less than 2-3 seconds), using the "Back" button on the next page may cause some browsers to move back to the redirecting page, whereupon the redirect will occur again. This is bad for usability, as this may cause a reader to be "stuck" on the last website.
  • A reader may or may not want to be redirected to a different page, which can lead to user dissatisfaction or raise concerns about security.[2]

Alternatives

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 it should be noted that 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:

<body onload="window.location = 'http://example.com/'">

<!-- Your content here -->

</body>

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 (parts of) the Web site without the need for a complete page refresh, but this would also require that the user enable JavaScript in their browser.

To redirect noscript browsers

Using the following technique, browsers that do not understand JavaScript can be redirected to alternative pages which are designed without requiring support for JavaScript.

For example, if the current URL is news.php, the browser redirects to news-nojs.php.

<noscript><meta http-equiv="refresh" content="0; url=news-nojs.php"></noscript>

References

  1. ^ Core Techniques for Web Content Accessibility Guidelines 1.0 - W3C Note 6 November 2000
  2. ^ Meta Refresh Tag, An About.com article covering the use of the tag for page reloading or redirection

External links