Skip to content

Instantly share code, notes, and snippets.

@nike-17
Created April 9, 2013 03:48
Show Gist options
  • Save nike-17/5342809 to your computer and use it in GitHub Desktop.
Save nike-17/5342809 to your computer and use it in GitHub Desktop.
JS redirect with referer
$(function() {
function navigateToUrl(url) {
var f = document.createElement("FORM");
f.action = url;
var indexQM = url.indexOf("?");
if (indexQM>=0) {
// the URL has parameters => convert them to hidden form inputs
var params = url.substring(indexQM+1).split("&");
for (var i=0; i<params.length; i++) {
var keyValuePair = params[i].split("=");
var input = document.createElement("INPUT");
input.type="hidden";
input.name = keyValuePair[0];
input.value = keyValuePair[1];
f.appendChild(input);
}
}
document.body.appendChild(f);
f.submit();
}
navigateToUrl("http://coccoc.local/");
});
@ducdhm
Copy link

ducdhm commented Apr 9, 2013

We can do it by creating an anchor (a tag) and fire this click event :) You can check it at https://gist.github.com/bobkhin/5342993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment