简体   繁体   English

更改url中的哈希值时,刷新浏览器上的浏览器后单击

[英]Refresh browser page on browser back click when changing hash value in url

I have a website with filters. 我有一个带有过滤器的网站。 I have appended hash whenever any filter is applied. 每当应用任何过滤器时,我都会附加哈希。 For example i have city, color filter. 例如我有城市,彩色滤光片。

URL/#color=red&city=Delhi URL /#color = red&city = Delhi

Now when someone clicks browser back on such url, it becomes URL/#color=red. 现在,当有人在该URL上单击浏览器时,它将变为URL /#color = red。 The city query string is removed by browser. 城市查询字符串被浏览器删除。

The problem is the page doesn't reload itself. 问题是页面不会重新加载自身。

$(window).on('hashchange', function () {
    window.location.reload(true);
});

But this is infinitely loading the page. 但这无限地加载页面。

Try history API https://developer.mozilla.org/en-US/docs/Web/API/History_API 试用历史记录API https://developer.mozilla.org/zh-CN/docs/Web/API/History_API

eg 例如

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");

Try turning off caching so that when you go back, the browser will automatically obtain a new page from the server... 尝试关闭缓存,以便当您返回时,浏览器将自动从服务器获取新页面...

More information here ... 更多信息在这里 ...

You may not want to hear this, but the HTML you have is not valid and needs to be fixed by converting the anchors # to proper query strings ? 你可能不爱听这个,但你有HTML是无效的,需要通过转换锚固定#适当的查询字符串? . This will allow the browser to go back and reload the page. 这将允许浏览器返回并重新加载页面。

You can do this using a find and replace in your HTML editor. 您可以使用HTML编辑器中的“查找并替换”来执行此操作。

If that's going to cause problems to the way you've implemented your filters, you'll need to update your filtering code. 如果这将对实现过滤器的方式造成问题,则需要更新过滤代码。 If you post that here we can help fix that. 如果您在此处发布,我们可以帮助您解决。

Hope that helps. 希望能有所帮助。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击浏览器后退按钮时刷新当前页面(chrome) - Refresh the current page when i click the browser back button(chrome) 浏览器后退按钮单击或页面刷新时发出警报 - Alert on Browser Back button click or page refresh 如何在浏览器回点击时强制页面刷新? - how to force page refresh on browser back click? 在浏览器中更改URL参数时刷新角度页面 - Angular page refresh on changing URL parameter in browser 单击后退按钮时重新加载浏览器页面 - reload browser page when click back button 如何在页面刷新或单击浏览器后退按钮后隐藏 div - How to hide div after page refresh or click browser back button 在后浏览器按钮上刷新页面 - Refresh page on back browser button 在浏览器上触发事件并强制刷新或使用新的URL重新加载页面 - Trigger event on browser back and force refresh or reload the page with new url 当浏览器中的一个 URL 被点击或者一个页面被回发时是否有一个全局的 JavaScript 事件 Vs 每个 URL 的点击事件 - Is there a global JavaScript event when a URL in browser is clicked or a page is posted back Vs click event of each URL 当我单击浏览器中的后退按钮时,我需要将上一页重新加载到“另一个 URL” - I need to reload the previous page to 'another URL' when I click on back button in browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM