【问题标题】:Add path to window.location without going to new pageAdd path to window.location without going to new page
【发布时间】:2022-12-28 00:29:04
【问题描述】:

Look at the example of the online store. https://online-store-rs.netlify.app/ When you click to button "smartphones", "Apple", or place ranges, window location paths changes to https://online-store-rs.netlify.app/?category=smartphones&brand=apple&price=90%E2%86%95899 How is it done? When in javascript I change window.location.path to something, page redirecting. How can I change only path without that redirecting?

【问题讨论】:

  • you might be referring to location.history - specifically history.pushState? That allows you to change the displayed URL ( address bar ) without reloading the page.

标签: javascript html


【解决方案1】:

Please use replaceState (for modern browsers) or pushState.

window.history.replaceState(data, title, url);
window.history.pushState(data, title, url);

【讨论】:

    猜你喜欢
    • 2020-01-01
    • 2022-12-02
    • 2022-12-02
    • 2011-04-06
    • 2023-02-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多