Remove Specific Parameters from URL
Hi,
Our landing page URLs contain numerous parameters. I would like to populate a variable with a subset of these.
For example:
Original: www.example.com/home.html?st=nc&leadsource=events&product=generic&vendor=abc&vanity_url=example.com-ncevents
Desired: www.example.com/home.html?leadsource=events&product=generic&vanity_url=example.com-ncevents
In this example, I have removed "st=nc" and "vendor=abc" as well as the "&"s.
Our real URLs can contain as much as 15 parameters and they're not always in the same order. I would also need to remove the associated "&" without removing the "?" if it's the first parameter.
Ali
----------------------------------------------------------------
After posting this I tried something that works but not well enough:
var OrigURL = "www.example.com/home.html?st=nc&leadsource=events&product=generic" var LSPos = OrigURL.indexOf('leadsource'); var LSPosEnd = OrigURL.indexOf('&',LSPos+1); var LSValue = OrigURL.substring(LSPos,LSPosEnd+1); var NewURL = OrigURL.replace(LSValue,""); _satellite.notify("OrigURL: "+OrigURL); _satellite.notify("LSPos: "+LSPos); _satellite.notify("LSPosEnd: "+LSPosEnd); _satellite.notify("LSValue: "+LSValue); _satellite.notify("NewURL: "+NewURL);This works in removing the leadsource parameter but it has several problems
(1) If .indexof() returns -1 it will continue anyways
(2) It relies on the next "&" which may not exist if it's the last parameter
(3) I need a way to nest multiple of these and have the process continue to other parameters even if one of them is not found.
Ali