简体   繁体   中英

window.location.href inserts new page inside of current page

New to JavaScript. I have an AJAX function that ultimately is intended to navigate to a new URL. However, instead of the new page appearing as if the user had typed the URL themselves, the new page is sort of 'inserte' inside the same div of the button that launched the script via its onclick handler. The line in question is this:

window.location.href("newpage.html");

What I want is the old page to be replaced by the new page and the old page to be retained in the browsing history.

Note that this script is called by a button inside of a form. I can show the whole code if it is helpful.

Thanks!

It's usually used as follows:

window.location.href = "newpage.html"

href is NOT a function, but a property .

References:

I think you may have been confused with window.location.assign("http://whatever") method

Caveat: href(url) may work on some browsers (IE???), but definitely not in FireFox - it gives an explicit "Not a function" error when run via JS-Execute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM