Skip to content

Instantly share code, notes, and snippets.

@Jamonek
Forked from benphelps/gist:931e0b7e4f36f430ba38
Created March 21, 2013 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jamonek/1ae01e2aa5359ea08110 to your computer and use it in GitHub Desktop.
Save Jamonek/1ae01e2aa5359ea08110 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) {
// get the #jump=url from the url
url_hash = window.location.hash.substr(1);
// make sure its actually a #jump=
if (url_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]['href'].indexOf('http') !== -1) {
element[i]['href'] = landing + element[i]['href'];
}
else {
element[i]['href'] = abs + landing + element[i]['href'];
}
}
}
hijack('http://ncat.edu/', 'ad.html#jump=');
@Jamonek
Copy link
Author

Jamonek commented Oct 13, 2014

Completely forgot about this.

@Jamonek
Copy link
Author

Jamonek commented Jan 12, 2016

Decided to make this public.

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