如何获取url地址后带的参数

url: http://www.xxxxxx.com/game/index.html#/?key=5161565

function getQueryString(name: string) { 
     // var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); 
     var result = window.location.href.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); 
     if (result == null || result.length < 1) {
         return ""; 
     } 
     return result[1];
 }
 
getQueryString('key');  // 5161565

你可能感兴趣的:(如何获取url地址后带的参数)