Search code examples
javascripthttp-redirectmeta-tagshttp-equiv

Javascript equivalent of http-equiv redirect


What is the equivalent of these two meta tags:

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

<meta http-equiv="refresh" content="35; URL=http://www.example.com/">

In JavaScript?


Solution

  • If you just need a refresh you can use window.location.reload().

    If you need it to fire after 35 seconds use setTimeout(function() { window.location.reload(); }, 35000);

    To redirect to another page you can use either window.location.replace('http://www.example.com') to make sure the browser Back button skips the previous page, or window.location = 'http://www.example.com' to preserve the browser history.