我有一個使用vbscript的經典asp網站。如何檢查用戶是否來自我的網站上的某個目錄?我有這個代碼asp classic中提供了通配符?
<%Response.Write(Request.ServerVariables("http_referer"))%>
其中寫道:http://example.com/mobile/REFER.asp。我想寫一個if/else語句,首先檢查引用的URI是否在目錄http://example.com/mobile/中。
所以我的代碼應該像下面的東西。但我不確定語法。是否有這樣的通配符字符是asp?
<% Request.ServerVariables("http_referer") == "http://example.com/mobile/*"
最後,我想用它來寫一個if/else語句
<% if Request.ServerVariables("http_referer") != "http://example.com/mobile/*" then
null; elseif (screen.width <= 699) {
document.location = "/mobile/mobile_home.asp";
} %>
===
截至加速編輯@ mikeyq6的JavaScript樣本這裏面工作:
<script type="text/javascript">
if(document.referrer.indexOf('/mobile') > -1 &&
screen.width <= 699) {
document.location = "/mobile/mobile_home.asp";
}
</script>
記住,使用硬編碼的URL ISN」的任何方法特別是從維護的角度來看,這是最好的想法。如果您確實需要這樣做,請考慮在URL中存儲您希望在[應用程序](https://msdn.microsoft.com/zh-cn/library/ms525360(v = vs.90).aspx)對象級別變量,這樣你就可以在'global.asa'中定義它,並在需要時調用它。 – Lankymart