I have the following URL:
What I would like to do is add the
part of the URL to specific links on the page based on their ID’s. The ?code= and ?ref= are dynamic, so I would need to get the URL as a dynamic URL.
What would be the best way to do this?
Get everything after the
? and add those other links. The only care you need to take is appending an ? or & before the params depending on if the links already have a query string.
var params = window.location.href.split('?')
// get links somehow and then
var href = link.href
href += (href.indexOf('?') == -1) ? '?' : '&'
href += params
link.href = href
is the same as
var params = window.location.search.slice(1)
If you don’t need to drop the ? then you can simply reference location.search
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.