[英]JS redirect/window replace doesn't work if url is the same (but anchor added)
我想使用JS / jQuery重新加載當前頁面並跳轉到錨點。
我嘗試過使用:
window.replace('currentpage/#msg'+.message_id);
和
window.location.href ='currentpage/#msg'+.message_id;
兩者都更改了地址中的URL,但無法重新加載頁面。
還有其他方法嗎?
更改網址后調用:
window.location.reload(true)
有更多方法可以做到: http ://www.phpied.com/files/location-location/location-location.html :)
強制重定向的另一種方法是通過添加隨機元素來確保URL確實發生了更改。 我經常在URL末尾添加時間戳。
這具有額外的優點或缺點,即每個頁面加載對於緩存系統/ etc而言都是唯一的。 您可能會或可能不會想要這個。
首先獲取當前網址
var CurUrl = window.location;
現在,無需進一步更改瀏覽器中的重定向URL。
history.pushState(CurUrl, "OldPage", "NewPage");
現在,瀏覽器URL已更改,但頁面未重定向,然后再次獲取URL'。
var UrlRedirect = window.location;
在這里你可以寫你的代碼
完成重定向
window.location = UrlRedirect;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.