我有下面的链接。
http://tili-click.startboomservice.com/tracking/adClick?d=IAAAAAAgAAA6X
我需要得到的查询字符串与前问号 所以结果将是:
adClick
这必须在许多链接上做类似的模式,我无法找到像URL编码的解决方案,我使用的主机和路径名。
检查window.location,你会得到的想法,有更多的属性,将帮助你。例如,其中一些是。
window.location.href
window.location.hostname
window.location.search
window.location.pathname
你可以做这样的事情:
var queryString = window.location.search;
var paths = window.location.pathname.split("/")
var lastPath = paths[paths.length-1]
var rsult = lastPath+queryString;
你可以使用 URL.pathname()
和 .split()
字符串方法。
const url = new URL("http://tili-click.startboomservice.com/tracking/adClick?d=IAAAAAAgAAA6X");
const pathname = url.pathname.split('/');
console.log(pathname.pop());