【www.gdgbn.com--浏览器】

有时,您可能希望获得当前页面的网址是在浏览器窗口中显示网址。例如,如果您想让您的访客提交博客张贴到Digg您需要得到同样的确切网址。有很多其他原因也很多。这里就是你如何能够做到这一点。

下面的代码添加到页面:

<%
function curPageURL()
 dim s, protocol, port

 if Request.ServerVariables("HTTPS") = "on" then
   s = "s"
 else
   s = ""
 end if 
 
 protocol = strleft(LCase(Request.ServerVariables("SERVER_PROTOCOL")), "/") & s

 if Request.ServerVariables("SERVER_PORT") = "80" then
   port = ""
 else
   port = ":" & Request.ServerVariables("SERVER_PORT")
 end if 

 curPageURL = protocol & "://" & Request.ServerVariables("SERVER_NAME") &_
              port & Request.ServerVariables("SCRIPT_NAME")
end function

function strLeft(str1,str2)
 strLeft = Left(str1,InStr(str1,str2)-1)
end function
%>

现在,您可以得到当前页面的URL使用行

<%
  response.write(curPageURL())
%>
如果您的网页有你想要查询字符串信息以及您可以尝试这样的代码:

<%
  response.write(curPageURL() & "?" & Request.ServerVariables("QUERY_STRING"))
%>
下面的示例演示如何做到这一点:
<%
function curPageName()
 dim pagename

 pagename = Request.ServerVariables("SCRIPT_NAME")

  if inStr(pagename, "/") > 0 then
    pagename = Right(pagename, Len(pagename) - instrRev(pagename, "/"))
  end if

 curPageName = pagename
end function

response.write("The current page name is " & curPageName())
%>

本文来源:http://www.gdgbn.com/bangongshuma/23666/