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

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 /\/(.?*)\?/ Commented May 7, 2020 at 10:29
  • Use location.pathname.split('/') to get an array of parts, go from there Commented May 7, 2020 at 10:30
  • another issue i encounter is that: urlEncode.host +urlEncode.pathname gets me: adClick when i just need to get tracking Commented May 7, 2020 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 Commented May 7, 2020 at 10:34

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

@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.
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;

Comments

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());

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.