0

i have the following link:

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

I need to get the query string with before question mark so the result would be

adClick

this must done on many link with similar pattern. I couldnt find solution like url encode that i use for host and pathname

deals4us3
  • 35
  • 1
  • 4
  • where is this link? a string in a variable? ...`adClick` is NOT part of the query string, it's the last part of the "pathname' something like `/\/(.?*)\?/` – Jaromanda X May 07 '20 at 10:29
  • Use `location.pathname.split('/')` to get an array of parts, go from there –  May 07 '20 at 10:30
  • another issue i encounter is that: urlEncode.host +urlEncode.pathname gets me: adClick when i just need to get tracking – deals4us3 May 07 '20 at 10:32
  • what? if that's "another problem" you need to ask "another question" - hopefully with some explanation of what you have, what you want, what you get instead of what you want – Jaromanda X May 07 '20 at 10:34

3 Answers3

0

check window.location you will get idea, there are more properties that will help you. e.g. some of them are:

window.location.href
window.location.hostname
window.location.search
window.location.pathname
Tranquillity
  • 237
  • 2
  • 9
  • @JaromandaX I am giving just hint where to look, you can find you answer in the window.location object. With this you can explore more about location object and use what is needed and helpful for the future as well. – Tranquillity May 07 '20 at 10:33
0

You can do something like:

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

var rsult = lastPath+queryString;
Hamza Arshad
  • 856
  • 5
  • 8
0

You can use URL.pathname() and .split() string method:

const url = new URL("http://tili-click.startboomservice.com/tracking/adClick?d=IAAAAAAgAAA6X");
const pathname = url.pathname.split('/');
console.log(pathname.pop());
ROOT
  • 11,363
  • 5
  • 30
  • 45