Skip to content

How do redirect to another webpage?

  • by

To redirect to another webpage, you can use the window.location object in JavaScript. Here’s an example of how to do this:

// Redirect to another webpage
window.location.href = "";
// OR
location.href = 'newPage.html';

When you set this property to a new URL, the browser will automatically redirect to the specified webpage. You can also use the window.location.replace() method to redirect to a new webpage.

// Redirect to another webpage

Redirect to another webpage example

Simple example code.

<!DOCTYPE html>
    <title>Redirect to Another Webpage</title>

    <h1>Welcome to my webpage!</h1>

    <p>Click the button below to redirect to another webpage:</p>

    <button onclick="redirectToAnotherWebpage()">Go to</button>

        // Function to redirect to another webpage
        function redirectToAnotherWebpage() {
            window.location.href = "";



How do redirect to another webpage?

To trigger the redirect using jQuery, you can attach an event listener to an element on the page, such as a button or a link.

<button id="myButton">Go to</button>

// Attach an event listener to the button
$("#myButton").click(function() {
    // Redirect to another webpage
    window.location.href = "";

Do comment if you have any doubts or suggestions on this webpage topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *