首页 > 解决方案 > JavaScript:如何在同一域中从“example.com/page1”重定向到“example.com/page2”?

问题描述

我想要一个使用 JavaScript 重定向https://www.example.com/collections/all?sort_by=best-sellinghttps://www.example.com/collections/all同一个域名的 JavaScript 代码。

标签: javascript

解决方案


如果您使用window.location.assign("yoururl")它会导致加载新文档。如果您使用window.location.replace("yoururl")它,它将替换当前文档并用该 URL 替换当前历史记录,这样您就无法返回上一个加载的文档。

参考:https ://developer.mozilla.org/fr/docs/Web/API/Location/assign 参考:https ://developer.mozilla.org/fr/docs/Web/API/Location/replace


推荐阅读