2016-01-24 32 views
1

我目前在一個網址像這個 -使用Javascript - 頁面重載不與散列值工作

http://localhost:8000/settings#social_accounts

我要重新加載這個頁面JS/jQuery,這樣我可以有我確切的URL與散列。

所以我做了什麼是 -

路1

location.reload(); 

路2 -

location.reload(true); 

方式3-

window.location.replace(window.location.href); 

路4-

window.location.href += window.location.hash; 
location.reload(window.location.href); 

但沒有任何工作。每天的這個4路是給我一個重定向到

http://localhost:8000/settings

但我想重定向URL - http://localhost:8000/settings#social_accounts

任何人都可以請幫助?

+0

使用window.location.href,所以window.location.href = window.location.href –

+0

這是奇數行爲' location.reload()'工作正常**如果瀏覽器首先請求URL爲has,而不是用歷史記錄API修改URL –

+0

您是否擁有#social_accounts id的div? –

回答

0

我已經解決了它喜歡這 -

window.location.replace(window.location.href + '#' + window.location.hash.substr(1));

相關問題