#window.location.replace not redirecting to correct path?

6 messages · Page 1 of 1 (latest)

torn junco
#

I have the following code in an HTML file :

<button onclick="window.location.replace('..\Login\login.html');">
Login</button>

(Attemping to make a login page)

However this button links to ..\Homepage/..Loginlogin.html instead (obviously not a valid path). Any reason why this could be happening?

hushed hull
#

Use forward slashes not back slashes. Only Windows file paths use back slashes. Web URLs and Unix file paths all use forward slashes even if referencing a file on a Windows system.

If you want a URL to be relative to the current page do not start the URL with a slash. If you want it to be relative to the domain start it with a slash.

So when you're at example.com/hello

some/page would go to example.com/hello/some/page

/some/page would go to example.com/some/page (notice hello isn't in the URL now)

#

I do not think JavaScript will honor .. in a URL btw. I'm not 100% but I think that's the case.

torn junco
#

it does seem as if .. does still work

#

what's strange is that I'd been using backslashes so far in other links in my code