Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML redirect on page load

Tags:

I need one of my website pages to instantly redirect to another upon loading. The refresh HTML command does not work, as it does not check whether or not a certain url is being loaded. Also javascript will work too.

like image 523
Matthew Avatar asked Sep 30 '17 00:09

Matthew


People also ask

How do I redirect to another page on load?

To redirect from an HTML page, we use the META Tag. Along with this, we also use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value in the content is the number of seconds; you want the page to redirect after.

How do you redirect a load in HTML?

To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

How do I redirect a section of a page in HTML?

Method 1: Using HTML: One can use the anchor tag to redirect to a particular section on the same page. You need to add ” id attribute” to the section you want to show and use the same id in href attribute with “#” in the anchor tag.

How do I redirect to another link in HTML?

The simplest way to redirect to another URL is to use an HTML <meta> tag with the http-equiv parameter set to “refresh”. The content attribute sets the delay before the browser redirects the user to the new web page. To redirect immediately, set this parameter to “0” seconds for the content attribute.


1 Answers

You can wait for a load event with JavaScript and use one of either:

window.onload = function() {
    // similar behavior as clicking on a link
    window.location.href = "http://stackoverflow.com";
}

or

window.onload = function() {
    // similar behavior as an HTTP redirect
    window.location.replace("http://stackoverflow.com");
}

Source: How to redirect to another webpage?

like image 90
DavSanchez Avatar answered Nov 27 '22 07:11

DavSanchez