![](/img/trans.png)
[英]JavaScript window.location.href not working in localhost
[英]javascript window location get path of website to redirect to between localhost and actual domain
我希望能夠在我的網站注銷時將我的用戶重定向回主頁/登錄,如果我只是重定向到網站本身,這很容易做到,IE http://www.example.com/
但是,如何我可以在localhost上確定我的網站的根文件夾路徑嗎?
例如,我的一些網站位於: localhost/folder1/websiteBackup/
,其中一些位於: localhost/
結合它的最佳方法是什么,這樣一行代碼將適用於localhost和域名?
使用相對路徑而不是絕對路徑。 例如,而不是
/somePage.html
你可能會寫
../../somePage.html
如果腳本是共享的,並且您不知道它相對於頁面的位置,請考慮在單獨的<VirtualHost>
上進行開發,以使您的環境匹配。
這對我有用......運氣好
url:'<%=VirtualPathUtility.ToAbsolute("~/Include/ctnrls/Data.aspx") %>',
但我在IIS中映射我的虛擬路徑
document.location =
document.location.href.indexOf('localhost') >=0 ?
document.location.href.split('localhost')[1] + 'index.htm' :
'index.htm';
我建議使用一些服務器端會話變量(PHP / ASP)並為它們分配根路徑。 然后你可以隨時使用它們。
session("rootPath") = "/RootFolder/your-filename" (for ASP/VBScript)
以后在你的JS代碼中使用它們來重定向。
var path = '<%= session("rootPath")%> (JS code)';
檢查我在這里詢問的類似問題,了解有關相對路徑,相對根路徑和絕對根路徑的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.