Skip to content
Advertisement

How can I redirect from one HTML file to another using javascript (the files are local)?

index.html file path: /Users/nixon/Documents/Website Development/Pers Website/index.html

loginpage.html path: /Users/nixon/Documents/Website Development/Pers Website/loginpage.html

JavaScript

—UPDATE AS OF 08/08/2020—

Tried updating the code to this and it still didn’t work. HTML:

JavaScript

JS:

JavaScript

No errors in console: https://gyazo.com/29a2084c082f66f943795ecfef3b3909

Advertisement

Answer

[1.0] Your onclick needs parenthesis.

[1.1] You could do an event listener instead. Doing it this way, you’ll omit the parenthesis

[1.2] If you aren’t doing anything else other than loading a new page with the javascript, you don’t need javascript for that. anchor elements are meant for navigating to webpages.

[1.3] replace() is a part of the location object. Not the window. Instead of window.replace() it should be window.location.replace()

[1.4] I had previously mentioned replace, but noticed that this keeps you from being able to use the back button. If you use assign instead, the back button will work normally.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement