js检测网址中是否存在get参数

var ntype = isNtype();
//检测是否存在ntype参数
function isNtype(){
    var url = document.location.href;
    if(url.indexOf('ntype') > 0){
        return 1;
    }else{
        return 0;
    }
}

Tags: javascript

仅有一条评论

  1. say

    var fromid2 = getUrlParam('openid');

    function getUrlParam(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r!=null) return unescape(r[2]); return null; //返回参数值
    }

添加新评论