JavaScript get the doGet parameters

在javascript中也可以模仿jsp取得doGet的參數喔∼
下面是寫法跟範例:
/*取得doGet url中某個名稱變數的值*/ 
function gup( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
/*使用gup取得doGet參數值,並加到redirect的網址後面*/ 
if(gup('path') != null && gup('path') != ''){
document.location=document.location=(baseUrl+gup('path'));
} else {
alert('Sorry, parameter error!');
}

這個網誌中的熱門文章

Bash判斷參數是否存在

Node.js package : forever