`

js获取url参数

    博客分类:
  • web
阅读更多

iframe.load('showbody/servermonitor/servermonitor.html?ip=10.24.1.18&id=subsys&text=opermain&status=online&desc=子系统');

打开该页面,在该页面中获取url后面的参数方法:

 

function GetUrlParams(){

    //获取url中"?"符后的字串

    var url = location.search; 

    var theParams = new Object();

    if(url.indexOf("?") != -1){

        var str = url.substr(1);

        strs = str.split("&");

        for(var i = 0; i < strs.length; i++){

            theParams[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);

        }

    }

    return theParams;

}

 

然后

 

Ext.onReady(function () {

var urlParams = GetUrlParams();

 

Platform.app = {

serversCatalog: [

{

"title": urlParams['ip'],

"items": [

{

"id": urlParams['id'],

"text": urlParams['text'],

"ip":urlParams['ip'],

"url": "'cnaps2'",

"icon": "cnaps2.gif",

"desc": urlParams['desc'],

"status": urlParams['status']

},

 

这样就可以获取参数了。

分享到:
评论
1 楼 yxc_gdut 2013-09-27  
function getParam(url){
	var reg=/[?&]([^=]+)=([^&]+)/g,
		a,
		param={};
	while(a = reg.exec(url)){
		param[a[1]] = decodeURI(a[2]);
	}
	return param;
}

相关推荐

Global site tag (gtag.js) - Google Analytics