給定一個網址www.site.com/test
,我怎麼能路由到www.site.com/#testinner
與JavaScript,沒有硬編碼基地網址?通過路由 - 我的意思是包括刷新/頁面加載。給定一個網址www.site.com/test,用javascript轉到www.site.com/#testinner,沒有硬編碼基址url
這給了我settings#lol
:
var desiredBase = window.location.protocol + "//" + window.location.host + "/";
var path = '#lol';
window.location.href = desiredBase + path;
location.reload();
你男人像'window.location.href = window.location.origin + '/' + path'? –
@BenjiLees不重新加載。 – RobVious
真的嗎?你在哪裏運行腳本?我只是把它放在我的瀏覽器控制檯中,它運行良好。您不必使用重新加載方法,該方法旨在重新加載當前頁面。 –