请问这个URL链接中包含‘指定参数’的长尾词是什么?
- 内容介绍
- 文章标签
- 相关推荐
本文共计381个文字,预计阅读时间需要2分钟。
javascriptfunction getAllUrlParams(url) { // Get query string from url (optional) or window.location.search 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) { // Split the query string into key-value pairs var pairs=queryString.split('&');
// Iterate over each pair for (var i=0; i // Decode the key and value from URI components var key=decodeURIComponent(pair[0]); var value=decodeURIComponent(pair[1]); // If the key already exists, then it's an array if (obj.hasOwnProperty(key)) { // If it's not already an array, convert it into one if (!Array.isArray(obj[key])) { obj[key]=[obj[key]]; } obj[key].push(value); } else { // Otherwise, just store the key-value pair obj[key]=value; } } } return obj;} 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('127.0.0.1:5000/app/index.html?code=KXMvRUkC92WaJ6n3vELMU3iK2128879&state=').code;
console.log(x);
本文共计381个文字,预计阅读时间需要2分钟。
javascriptfunction getAllUrlParams(url) { // Get query string from url (optional) or window.location.search 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) { // Split the query string into key-value pairs var pairs=queryString.split('&');
// Iterate over each pair for (var i=0; i // Decode the key and value from URI components var key=decodeURIComponent(pair[0]); var value=decodeURIComponent(pair[1]); // If the key already exists, then it's an array if (obj.hasOwnProperty(key)) { // If it's not already an array, convert it into one if (!Array.isArray(obj[key])) { obj[key]=[obj[key]]; } obj[key].push(value); } else { // Otherwise, just store the key-value pair obj[key]=value; } } } return obj;} 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('127.0.0.1:5000/app/index.html?code=KXMvRUkC92WaJ6n3vELMU3iK2128879&state=').code;
console.log(x);

