Rene Zammit
Rene Zammit

Reputation: 1151

get parameter from url and save the parameter in other links on the same page

I have a problem and i need some help please. I have this page with a parameter http://www.webxpress.com/landingpage.asp?label=CSU...

Now in this page i have 3 buttons with the following links:
www.webxpress.com/button1.asp
www.webxpress.com/button2.asp
www.webxpress.com/button3.asp

All i want is to add the parameter in the button links (depending on the parameter in the url)... For example: from www.webxpress.com/button1.asp the link comes www.webxpress.com/button1.asp?label=CSU (this parameter is taken from the url).

Can someone please help me and give me some tips because i do not know from where i should start.

Upvotes: 0

Views: 730

Answers (2)

mhitza
mhitza

Reputation: 5715

You can use document.location.search as the previous comment suggested and extract the part you are interested in. Afterwards you can iterate over every link in the page with document.links and update them.

For example:

dl = document.links;
for(i = 0, len = dl.length; i < len; i++) {
  dl[i].href = dl[i].href + '&label=CSU";
}

Upvotes: 0

user460331
user460331

Reputation: 81

You can use:

document.location.search

which returns the part of the URL after the ? sign (including the question-mark).

To test that this is what you want, try to navigate with your browser on a page with such parameters, and then type in the address bar of the browser:

javascript:alert(document.location.search)

Then, you can use document.write to write the links with this value at the end:

document.write("<a href='http://.../button1.asp" + document.location.search + "'>button1 link</a>");

Upvotes: 1

Related Questions