在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