如何更改当前网址? [英] How can I change the current URL?
本文介绍了如何更改当前网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码可从JavaScript内更改页面:
I have the following code that changes the pages from within JavaScript:
var newUrl = [some code to build up URL string];
window.location.replace(newUrl);
但是它不会更改顶部URL,因此当有人单击后退按钮时,它不会返回上一页.
But it doesn't change the top URL, so when someone clicks the back button it doesn't go back to the previous page.
我如何让JavaScript也更改顶部URL,以便浏览器后退按钮起作用.
How can I have JavaScript change the top URL as well so the browser back button works.
推荐答案
document.location.href = newUrl;
https://developer.mozilla.org/zh- US/docs/Web/API/document.location
这篇关于如何更改当前网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文