javascript - 字符串而不是 window.location.search
问题描述
如何从 javascript 中的字符串获取 url 参数?而不是使用 window.location.search。例如,让 ="https://google.com/hello?name=roger&age=20" 我需要获取我在此示例中找到的所有参数,但它使用 window.location.search
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
解决方案
推荐阅读
- node.js - 通过机器人访问网页
- javascript - 将 Laravel Paginator 与 Ajax 请求一起使用
- linkedin-api - Angular 2中的Linkedin成员资料
- sql - 如何从 BigQuery 中的字符串中仅删除字母?
- python - 使用字符串键创建数据框字典
- sql - SSRS 过滤 Tablix 列
- excel - 我希望从 Powershell 更改 Excel 中的数据。
- adfs - 在 AD 中禁用时注销用户
- debugging - 清除 IE11 开发者工具中的“网络”选项卡
- php - 使用缓存使用 XMLReader PHP 解析 xml 文件