在asp中,我們很多時候獲取url都是利用javascript來實現的,這個很簡單,用window.location.href就可以獲得了URL的全部路徑,包括後面的參數,然後再用split函數來分離就好了
但在asp中,我們很多時候只想:
response.Write"SCRIPT_NAME獲取的值:" &Request.ServerVariables("SCRIPT_NAME")&"
"
'=========================
'獲取當前Url參數的函數
Private Function GetUrl()
Dim ScriptAddress,M_ItemUrl, M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得當前地址
M_ItemUrl = ""
response.Write(Request.QueryString&"
")
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
'如果頁面傳遞參數是用page變量,那麼判斷一下page是否已經使用,避免重復!
If InStr("page",M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
end if
GetUrl = ScriptAddress & M_ItemUrl
if instr(1,GetUrl,"?",1)<1 then
GetUrl=GetUrl&"?"
end if
End Function
'=============================
response.Write GetUrl