-1

Incredibly, I've been unable to find any JS code for this scenario:

If people come to http://example.com I don't need anything to happen.

But if they come in as http://example.com/?ref=producthunt, we need to redirect them to another page, like http://example.com/custom-landing.html.

So sorry for the vague question but I've been Googling for hours now and no luck.

CollinD
  • 7,304
  • 2
  • 22
  • 45
user3236756
  • 79
  • 1
  • 7
  • 1
    That would be a combination of [this](http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter) and [this](http://stackoverflow.com/questions/4744751/how-do-i-redirect-with-javascript). – AryanJ-NYC Jul 26 '16 at 18:33
  • you can use window.location.search to get the parameter – slashsharp Jul 26 '16 at 18:33

1 Answers1

-1

use this function with the parameters matters

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

Code Source: first answer here How can I get query string values in JavaScript?

and than create your link to redirect, and finally redirect usingo window.location = 'tour-url';

Community
  • 1
  • 1