在url中的路径名后获取查询字符串[重复]。

问题描述 投票:-1回答:3

我有下面的链接。

http://tili-click.startboomservice.com/tracking/adClick?d=IAAAAAAgAAA6X

我需要得到的查询字符串与前问号 所以结果将是:

adClick

这必须在许多链接上做类似的模式,我无法找到像URL编码的解决方案,我使用的主机和路径名。

javascript urlencode
3个回答
0
投票

检查window.location,你会得到的想法,有更多的属性,将帮助你。例如,其中一些是。

window.location.href
window.location.hostname
window.location.search
window.location.pathname

0
投票

你可以做这样的事情:

var queryString = window.location.search;
var paths = window.location.pathname.split("/")
var lastPath = paths[paths.length-1]

var rsult = lastPath+queryString;

0
投票

你可以使用 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());
© www.soinside.com 2019 - 2024. All rights reserved.