Skip to content

Instantly share code, notes, and snippets.

@benphelps
Last active December 15, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benphelps/931e0b7e4f36f430ba38 to your computer and use it in GitHub Desktop.
Save benphelps/931e0b7e4f36f430ba38 to your computer and use it in GitHub Desktop.
// this goes into every page where the hijack will take place
// or where the hijack will land
function hijack (abs, landing) {
// make sure its actually a #jump=
if (window.location.hash.indexOf("#jump=") !== -1) {
// trim off jump= and redirect
url = window.location.hash.substr(6);
window.setTimeout(function(){
window.location = url;
}, 2000);
}
// capture all a href elements and replace with landing
var element = document.getElementsByTagName('a');
for (var i = 0; i < element.length; i++) {
// check if the url is absolute or not
if (element[i].getAttribute('href').indexOf('http') == 0) {
element[i]['href'] = landing + element[i].getAttribute('href');
}
else {
element[i]['href'] = abs + landing + element[i].getAttribute('href');
}
}
}
hijack('http://ncat.edu/', 'ad.html#jump=');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment