Skip to content

Instantly share code, notes, and snippets.

@Nils-van-Kleef
Last active January 31, 2017 13:43
Show Gist options
  • Save Nils-van-Kleef/643f1d24c42b27b3bcadc864e0efd6f9 to your computer and use it in GitHub Desktop.
Save Nils-van-Kleef/643f1d24c42b27b3bcadc864e0efd6f9 to your computer and use it in GitHub Desktop.
Redirect: adds query-parameter at the end
/* _optimizely_redirect=http://www.example.com */
var qp_addition = "newSearchWeb=true";
if (window.location.href.indexOf(qp_addition) < 0) {
var _optly = {redir: document.createElement("a")};
_optly.redir = {protocol: "https:" == document.location.protocol ? "https://" : "http://",
domain: window.location.hostname,
entire_url: window.location.href,
query: window.location.search
};
if (_optly.redir.query.length == 0) {
qp_addition = "?"+qp_addition;
} else {
qp_addition = "&"+qp_addition;
}
_optly.redir.href = _optly.redir.entire_url + qp_addition;
window.location.replace(_optly.redir.href);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment