js获取url上的指定参数
JS 获取 参数 指定 url
2023-09-11 14:16:54 时间
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
// we'll store the parameters here
var obj = {};
// if query string exists
if (queryString) {
// stuff after # is not part of query string, so get rid of it
queryString = queryString.split('#')[0];
// split our query string into its component parts
var arr = queryString.split('&');
for (var i = 0; i < arr.length; i++) {
// separate the keys and the values
var a = arr[i].split('=');
// in case params look like: list[]=thing1&list[]=thing2
var paramNum = undefined;
var paramName = a[0].replace(/\[\d*\]/, function (v) {
paramNum = v.slice(1, -1);
return '';
});
// set parameter value (use 'true' if empty)
var paramValue = typeof (a[1]) === 'undefined' ? true : a[1];
// if parameter name already exists
if (obj[paramName]) {
// convert value to array (if still string)
if (typeof obj[paramName] === 'string') {
obj[paramName] = [obj[paramName]];
}
// if no array index number specified...
if (typeof paramNum === 'undefined') {
// put the value on the end of the array
obj[paramName].push(paramValue);
}
// if array index number specified...
else {
// put the value at that index number
obj[paramName][paramNum] = paramValue;
}
}
// if param name doesn't exist yet, set it
else {
obj[paramName] = paramValue;
}
}
}
return obj;
};
var x = getAllUrlParams('http://127.0.0.1:5000/app/index.html?code=KXMvRUkC92WaJ6n3vELMU3iK2128879&state=').code;
console.log(x);
相关文章
- Node.js:上传文件,服务端如何获取文件上传进度
- h5 录音 自动生成proto Js语句 UglifyJS-- 对你的js做了什么 【原码笔记】-- protobuf.js 与 Long.js 【微信开发】-- 发送模板消息 能编程与会编程 vue2入坑随记(二) -- 自定义动态组件 微信上传图片
- js 获取文件本地路径
- JS子页面如何获取父页面的变量、对象、方法
- Vue - 在纯 JS 文件中调用自定义组件 / 类似 ElementUI 弹框组件 Message、Modal(在纯 js 文件中通过 import 方式引入并调用弹框模态框组件显示出来,)
- js获取数组对象再多数组中出现次数
- js 时间处理函数 获取今天的前几天和后几天的任意一天
- 小程序 js中获取时间new date()的用法(网络复制过来自用)
- JS中的事件类型和事件属性的基础知识
- JS获取地址栏参数转换为对象
- jquery.params.js,Jquery获取页面参数,js获取页面参数
- Jquery获取html参数, jquery.params.js 获取参数
- JS获取所有LI中第三个<SPAN>
- JS教程之使用 P5.js 构建一个贪吃蛇游戏(教程含源码)
- JS模板引擎handlebars.js的简单使用
- JS 获取URL参数
- JS 工具函数 方法(其中js的crc32和php的crc32区别)
- [js高手之路]html5 canvas动画教程 - 下雪效果
- [js高手之路] dom常用API【appendChild,insertBefore,removeChild,replaceChild,cloneNode】详解与应用
- js获取html5 audio 音频时长方法
- js解析url参数如http://www.taobao.com/index.php?key0=21&key1=你哈&(获取key0和key1的值)
- js 正则去重
- js获取单选button的值
- three.js例子本地部署
- 利用js、css、html固定table的列头不动