How do I make a page redirect in a website?

Please tell me. I want to make a page that redirects to my pokemon trades.

Hey @lettucecrab,

You can do this using JavaScript by placing the following piece of code in your script.js:

window.onload = function() {
  window.location.href = "<THE SITE URL TO REDIRECT TO>";
}

Note that the redirect happens on onload of the page. If you want to redirect on mouse click, just use <a></a> tags as hyperlink.

Also, according to W3Schools.com (https://www.w3schools.com/howto/howto_js_redirect_webpage.asp), you could also use

window.location.replace("http://www.w3schools.com");

but the difference between href and replace, is that replace() removes the URL of the current document from the document history, meaning that it is not possible to use the “back” button to navigate back to the original document.

Hope this helps!

Hey there!

There’s another and simple way if you’re using Express.

app.get('/mypage', (req, res) => {
    res.redirect('https://link.com');
});

Happy Glitching!

1 Like