Html redirect new page

How to Easily Make HTML Redirect to Another Page

TL;DR – HTML redirect takes a website visitor to another site automatically.

Contents

What is an HTML Redirect?

A redirect happens when a user enters a URL, but it changes, and the browser takes them to a different one instead. Website creators rely on them when they need to change the structure of their site or the location of a particular page. Of course, you may redirect to a completely different website as well.

When working with Hypertext Transfer Protocol (HTTP), you need to have a basic understanding of its response codes. They contain three digits, first of which defines their type:

Let’s say you closed your old website and opened a new one. If a user types a URL of the old one into their browser, it will return the response code 404 (Not Found). However, if you use an HTML redirect, the user will get either 301 (Moved Permanently) or 302 (Found). This code is invisible to the user, but the browser understands it and redirects the user to the new URL in moments.

The Syntax for HTML Redirect Code

The HTML redirect is also known as the meta refresh redirect, or simply HTML meta redirect. It allows you to choose whether you need an immediate or a delayed redirect. If you specify the delay time in seconds, the user will see the old page for exactly that long.

To make a page in HTML redirect to another page, you should follow this syntax:

meta http-equiv="refresh" content="time; URL=new_url" />

As you can see, it requires two parameters:

  • time represents the delay before the browser redirects the user to a different page. Define it in seconds, or enter a 0 if you need an immediate HTML redirect.
  • new_url represents the URL address you need to redirect your user to after the delay.

In the example below, you can see the HTML redirect code that takes the user to BitDegree’s website with a delay of five seconds:

meta http-equiv="refresh" content="5; URL=https://www.bitdegree.org/" />
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
Читайте также:  Пакет yahoo finance python

Why Delay a Redirect in HTML?

If you’re not sure why you should delay your HTML meta redirect, think about a chance to set a message for the user. You could inform them the page has moved, and then promptly send them to the new one.

Another important reason is the slight chance of the tag not being rendered correctly. This might happen if the user is using some ancient browser. In this case, you may add a direct link to the old page which the user might click manually if the HTML redirect code fails.

head> meta http-equiv="refresh" content="5; URL=https://www.bitdegree.org/" /> head> body> p>If you are not redirected in five seconds, a href="https://www.bitdegree.org/">click here a>. p> body>

As you can see, all you need to add a direct clickable link is a pair of anchor tags. Make sure to place it in the section and not the with the HTML meta redirect tag: there is no use for a clickable link that a user cannot see in the first place.

HTML Redirect: Useful Tips

  • If you don’t define a new URL address for the redirect, HTML page will simply reload itself after the time specified. It can be useful when you need to refresh dynamic content.
  • We’d advise you to avoid delays shorter than 3 seconds, as that makes it virtually impossible for the user to click the Back button on their browser.
  • Be careful not to overuse HTML meta redirects: if your website has a ton of them, the search engines may think it contains spam and remove it from their index.
  • You can also create redirects with PHP, JavaScript, Ruby on Rails, and Python Flask, as well as in the Apache, Nginx, and Lighttpd web servers.

Источник

How to Redirect a Web Page in HTML

To tell search engines and website visitors that your web page has permanently moved to a new location with an equivalent content use a 301 redirect. The code “301” is interpreted as “moved permanently”. (Learn more about HTTP Status Codes).

How to redirect to another URL

content="0; url='https://www.w3docs.com'" />

If you want your redirection to occur in an exact time, just specify your preferred parameter (in seconds) for the content . Let’s consider an example, where we set «7» seconds as redirection time.

Some browsers don’t render the refresh tag correctly, so before the next page loads, the user can see a flash as a page.

content="7; url='https://www.w3docs.com'" />

Some old browsers don’t refresh correctly when you add a quick link. In that case, you can add an anchor link to let the user follow.

Example of redirecting a web page:

html> html> head> meta http-equiv="refresh" content="7; url='https://www.w3docs.com'" /> head> body> p>You will be redirected to w3docs.com soon! p> body> html>

How to redirect to a new page without leaving the current page:

If you want to redirect to another website without leaving the current website and open a link that redirects to an HTML document, you can use the anchor tag with the «target» attribute set to «_blank». This will open the link in a new window or tab, while the current website remains open.

Читайте также:  Php get only numbers

Here’s an example of how to use it:

html> html> head> title>Redirecting without leaving the current page title> head> body> a href="https://www.w3docs.com" target="_blank">Click here to go to W3docs.com a> body> html>

In this example, clicking on the link will open «https://www.w3docs.com» in a new window or tab, while the current website remains open.

If you want to redirect to an HTML document instead of a website, you can use the same method by setting the link’s href attribute to the path of the HTML document you want to redirect to.

In this example, clicking on the link will open «example.html» in a new window or tab while the current website remains open.

Learn more about redirecting web pages with JavaScript, PHP, Apache and Node.js.

Источник

How to Redirect from One page to Another in HTML on Button Click?

Javascript Course - Mastering the Fundamentals

Let’s say you are designing an e-commerce website. A user lands on the log-in screen and fills in their details. What do you think will happen once the system verifies their credentials? You need to redirect them to their dashboard screen.

Redirect means changing the URL and web page. For example, let’s say you are currently browsing a current page of a website having URL example.com/page-a. Now, let’s say you click a link or button and transfer to another web page of the same website having URL example.com/page-b. This is called redirecting. It is widely used on a website.

Rediret JavaScript

Add an Image depicting redirecting in HTML from one page to another. Sample Image

There are several ways in which you can redirect a user:

  • The user can initiate redirecting in several ways.
  • They can be redirected by clicking on a button or clicking on a link.

In this article, we will explore several ways on who to redirect from one page to another in HTML on a button click.

Redirect using HTML Form Tag

The first way through which you can redirect from one page to another is by clicking a button. You can use a form for this purpose. The form tag in HTML has an attribute action where you can give the URL of the webpage where you want the form button to redirect. The form tag also has another attribute method. Just set the method attribute to POST , which means you are sending the data, and mention the URL in the action attribute. Once you submit the form, it will redirect you to the particular URL and webpage corresponding to that URL.

Читайте также:  Sql двойной запрос php

Syntax:

Code:

Form tags are widely used when you wish to submit user data to the backend, such as during sign-up or log-in.

Redirect using HTML Anchor Tags

If you wish to redirect the user, then you can use the good old anchor tags in HTML. All you need to do is provide the reference or URL of the webpage you need the user to redirect.

Syntax

Code:

Using location.href and location.replace

Apart from using HTML, you can also use Javascript to redirect users to your website. Javascript provides pre-built functions that one can use for redirecting. You can use location.href and location.replace to redirect the user from one page to another.

Syntax

You can add an event listener such as onClick to simulate a button click for redirecting. The location.replace function replaces the current URL with the one you provide, while the location.href creates a link between two pages. This means that once you click on a button that redirects using replace function, you cannot navigate back to the original document using the back button.

Code:

Redirect to Another Page after Form Submit HTML

If you want the user to be redirected after they have submitted their details, then you can use form tags. The attributes of form tags action and method can be used to achieve this. The action attribute specifies the path to which the URL will be redirected once the form is submitted. The method attribute specifies the HTTP method that needs to be used when submitting the form.

After you have filled out the form and clicked submit, then you will be redirected to the dashboard section of the website.

How to Redirect to Another Web Page Using jQuery or JavaScript?

The window.location.href and window.location.replace functions can be used in JQuery as well. You can add an event listener to an element in HTML. Then, you can use the location.href or location.replace method for redirecting.

Code:

In the above code, you have added the event Listener click that will activate when you click on the button. It will activate the function redirectFunction that will use location.href function to redirect to another page.

Conclusion

  • Redirecting refers to changing the URL of a website and the webpage associated with it when the user interacts with the website.
  • This article explains how to redirect from one page to another in HTML on a button click.
  • You can use form tags in HTML for redirecting. The action and method attributes can be used for redirecting to another page.
  • Anchor tags can also be used for redirecting. You can specify the URL in the href attribute of anchor tags in HTML.
  • Javascript and JQuery also provide support methods for redirecting. You can add event listener functions and call these methods to redirect the user to another page on the website.

Источник

Оцените статью