如何从 url 提取 &client=? [英] how to textract &client= from url?
本文介绍了如何从 url 提取 &client=?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的网址是 http://link-ads.blogspot.com/?url=http://could-be-any-url.com&name=123456789101112
使用 纯 javascript 我将如何提取 &client=
以便它提取 123456789101112
并将其设置为 var clientid = 123456789101112;
If my url is http://link-ads.blogspot.com/?url=http://could-be-any-url.com&name=123456789101112
using purely javascript how would I extract &client=
so it would extract 123456789101112
and set it as var clientid = 123456789101112;
推荐答案
var clientid = (window.location.search.match(/[?&;]name=(\d+)/) || [])[1];
如果它可以包含多个数字,请使用类似...
If it can contain more than numbers, use something like...
var clientid = (window.location.search.match(/[?&;]name=([^&;]+)/) || [])[1];
如果找不到参数,则返回undefined
.
If the param could not be found, it will return undefined
.
如果您需要更频繁地执行此操作,最好使用 通用解决方案.
If you need to do this more often, you'd be better off with a generic solution.
这篇关于如何从 url 提取 &client=?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文