php獲取跳轉(zhuǎn)前的url方法:1、獲取url帶questring參數(shù)的javascript客戶端方法;2、正則分析法,設(shè)置或獲取整個url為字符串,代碼為【alert(window.location.href)】。
php獲取跳轉(zhuǎn)前的url方法:
一:獲取url帶questring參數(shù)的javascript客戶端解決方案,相當(dāng)于asp的request.querystring,php的$_get
1.函數(shù):
<script language="javascript">function getrequest() {var url = location.search; //獲取duurl中"?"符后的字串var therequest = new object();if (url.indexof("?") !zhi= -1) {var str = url.substr(1);strs = str.split("&");for(var i = 0; i < strs.length; i ) {therequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);}}return therequest;}</script>2.然后通過調(diào)用此函數(shù)獲取對應(yīng)參數(shù)值:
<script language="javascript">var request = new object();request = getrequest();var 參數(shù)1,參數(shù)2,參數(shù)3,參數(shù)n;參數(shù)1 = request[''參數(shù)1''];參數(shù)2 = request[''參數(shù)2''];參數(shù)3 = request[''參數(shù)3''];參數(shù)n = request[''參數(shù)n''];</script>以此獲取url串中所帶的同名參數(shù)
二、正則分析法。
function getquerystring(name) {var reg = newregexp("(^|&)" name "=([^&]*)(&|$)","i");var r =window.location.search.substr(1).match(reg);if (r!=null) return(r[2]); return null;}alert(getquerystring("參數(shù)名1"));alert(getquerystring("參數(shù)名2"));alert(getquerystring("參數(shù)名3"));其他參數(shù)獲取介紹:
//設(shè)置或獲取對象指定的文件名或路徑。
alert(window.location.pathname);//設(shè)置或獲取整個 url為字符串。
alert(window.location.href);//設(shè)置或獲取與 url關(guān)聯(lián)的端口號碼。
alert(window.location.port);//設(shè)置或獲取 url的協(xié)議部分。
alert(window.location.protocol);//設(shè)置或獲取 href屬性中在井號“#”后面的分段。
alert(window.location.hash);//設(shè)置或獲取 location 或 url 的hostname 和 port 號碼。
alert(window.location.host);//設(shè)置或獲取 href屬性中跟在問號后面的部分。
alert(window.location.search);相關(guān)學(xué)習(xí)推薦:php編程(視頻)