gpt4 book ai didi

javascript - 重定向页面而不更改 url

转载 作者:行者123 更新时间:2023-12-01 01:52:07 25 4
gpt4 key购买 nike

我在索引页上编写了代码

window.location.replace(www.mysite.com/index2.html);

它会重定向,但它也会更改明显的 url。

例如当我运行 www.mysite.com/index.html

它应该运行 www.mysite.com/index2.html 页面,并且浏览器地址应显示 www.mysite.com/index.html

我想在 jquery 或 javascript 中执行此操作。

最佳答案

如果不欺骗浏览器的历史记录,就无法做到这一点。您可以在此处找到示例

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#section_4

否则,您可以使用框架在index.html中显示index2.html

请注意,并非所有浏览器都支持 history.pushState()

关于javascript - 重定向页面而不更改 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7180251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com