0
How can i redirect my web page without using window.location?
2 Respostas
+ 3
The comment in your code "...you don't want to have to use PHP" hints to me that it might be a key requirement.
PHP can (and in fact, should) send a redirect/location header in response to a server-validated form submission.
JS--the way it's used here--is client-side and not properly positioned to validate or send headers into the stream.
Other JS redirects that I've considered (e.g., navigate() ) are quirks / only for IE / not standard.
There is at least one other unusual option--insert a surprise meta redirect.
For the record, I advise against this (please redirect via webserver instead):
el = document.createElement("meta");
el.httpEquiv = "refresh";
el.content = "0; url=https://www.sololearn.com/";
document.getElementsByTagName("head")[0].appendChild(el);
IMO, that last item would _not_ be an acceptable answer for homework, only try it in a pinch.
0
If not using response headers to trigger a redirect, what's the reason for not using window.location?
Also, at what point will you want to trigger a redirect?
If triggered upon entering the page, then using the meta refresh could work. - As mentioned by Kirk Schafer
You could probably try triggering the click event to a link that points to the page for want to redirect to.
However, these are really hacky options.