We can use window.location.replace(…) or window.location.href to redirect a URL using JavaScript.
//Behave as an HTTP redirect window.location.replace("https://www.w3schools.blog"); //Behave as clicking on a link window.location.href = "https://www.w3schools.blog";
Related topics:
- What is JavaScript?
- JavaScript advantages and disadvantages
- Javascript External file
- Javascript isNaN()
- Javascript Undefined and Null
- Javascript Create object
- JavaScript access cookie
- Javascript read cookie
- Javascript get cookie by name
- Javascript detete cookie
- Javascript redirect URL
- Javascript print webpage
- Javascript exceptions