window.location force to update?

孤街醉人 提交于 2019-12-24 09:12:57

问题


I'm wondering is there a way for force window.location to update? I'm on a page which uses ajax to generate results. However, the URL stays the same in the bar and so I can't grab the real URL. I'm wondering.. how would I grab the URL? can I force window.location to update without refreshing the page?

An example of the sort of page I'm talking about is google instant!


回答1:


Are you looking to update the content and URL with AJAX? Just use History API provided by HTML5 browsers.




回答2:


No you can't. If you don't control the page and they are not updating the URL in a way, then there is nothing you can do.

But if you have control, then it is your responsibility to either use the fragment identifier or HTML5's new history API to update the adress. But even if you use the history API, window.location won't get changed.

Update:

Not 100% sure what Google Instant page you are talking about, but if it is the "normal" Google page, then you will see that the URL updates after 1 or 2 seconds after you typed the query.

So you could add an event listener for the hashchange event and then grab the URL from window.location.




回答3:


This question will be of interest:

How does facebook rewrite the source URL of a page in the browser address bar?




回答4:


changing location.hash with jquery ui tabs

Add this to your current trigger. (I'm aware this is jQuery but the logic is the same)



来源:https://stackoverflow.com/questions/4850349/window-location-force-to-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!