文章摘要
这篇文章描述了一个自定义JavaScript函数`GetUrl`,用于根据服务器变量生成合适的URL。该函数首先检查`HTTPS`标志,决定使用`http://`还是`https://`开头。接着,它拼接`SERVER_NAME`、`SERVER_PORT`(若不为80)、`URL`以及`QUERY_STRING`(若存在)来构建完整的URL。最后,该函数将生成的URL写入响应。文章的核心内容在于展示如何通过服务器变量动态控制URL的安全性和路径结构。
<%
function GetUrl()
on Error Resume Next
Dim strTemp
if LCase(request.ServerVariables(“HTTPS”))=”off” Then
strTemp=”http://”
Else
strTemp=”https://”
end if
strTemp=strTemp & Request.ServerVariables(“SERVER_NAME”)
if Request.ServerVariables(“SERVER_PORT”) <> 80 Then strTemp=strTemp & “:” & Request.ServerVariables(“SERVER_PORT”)
strTemp=strTemp & Request.ServerVariables(“URL”)
if trim(request.QueryString) <> “” Then strTemp=strTemp & “?” & Trim(Request.QueryString)
GetUrl=strTemp
End Function
response.write GetUrl()
%>
<%
function GetUrl()
on Error Resume Next
Dim strTemp
if LCase(request.ServerVariables(“HTTPS”))=”off” Then
strTemp=”http://”
Else
strTemp=”https://”
end if
strTemp=strTemp & Request.ServerVariables(“SERVER_NAME”)
if Request.ServerVariables(“SERVER_PORT”) <> 80 Then strTemp=strTemp & “:” & Request.ServerVariables(“SERVER_PORT”)
strTemp=strTemp & Request.ServerVariables(“URL”)
if trim(request.QueryString) <> “” Then strTemp=strTemp & “?” & Trim(Request.QueryString)
GetUrl=strTemp
End Function
response.write GetUrl()
%>
© 版权声明
文章版权归作者所有,未经允许请勿转载。