例:網頁URL : http://localhost:8086/index.aspx?topicId=361
1.設置或獲取 href 屬性中跟在問號后面的部分:window.location.search
alert(window.location.search); 則輸出:?topicId=361
2.設置或獲取對象指定的文件名或路徑:window.location.pathname
alert(window.location.pathname); //輸出:/index.aspx?topicId=361
3.設置或獲取整個 URL 為字符串 : window.location.href
alert(window.location.href); 則輸出:http://localhost:8086/index.aspx?topicId=361
4.設置或獲取與 URL 關聯的端口號碼:window.location.port
alert(window.location.port); 則輸出:8086
5.設置或獲取 URL 的協議部分:window.location.protocol
alert(window.location.protocol); 則輸出:http:
6.設置或獲取 href 屬性中在井號“#”后面的分段:window.location.hash
7.設置或獲取 location 或 URL 的 hostname 和 port 號碼:window.location.host
alert(window.location.host); 則輸出:http:localhost:8086
ps:window.location
屬性 描述
hash 設置或獲取 href 屬性中在井號“#”后面的分段。
host 設置或獲取 location 或 URL 的 hostname 和 port 號碼。
hostname 設置或獲取 location 或 URL 的主機名稱部分。
href 設置或獲取整個 URL 為字符串。
pathname 設置或獲取對象指定的文件名或路徑。
port 設置或獲取與 URL 關聯的端口號碼。
protocol 設置或獲取 URL 的協議部分。
search 設置或獲取 href 屬性中跟在問號后面的部分。
-----------------------------------------------------------------------------------------------------------------------------------------------------
C#后台獲取根目錄:Context.Request.Url.AbsoluteUri.Replace(Context.Request.RawUrl, "")
string url=Context.Request.Url.AbsoluteUri.Replace(Context.Request.RawUrl, "")+"/marster.aspx"
//url的值為 http://localhost:6514/marster.aspx