Skip to content

Instantly share code, notes, and snippets.

@akirchmyer
Created November 17, 2013 05:25
Show Gist options
  • Select an option

  • Save akirchmyer/7509664 to your computer and use it in GitHub Desktop.

Select an option

Save akirchmyer/7509664 to your computer and use it in GitHub Desktop.
A Pen by Andrew Kirchmyer.
<a href="http://synacor.com" id="link1">New Window</a>
<a href="http://synacor.com" id="link2">Same Window</a>
<a href="http://synacor.com" id="link3">Location Info</a>
// Use the following for a TRUE redirect, that will not throw the user forward on hitting the back button.
//window.location.replace('http://example.com');
$('#link1').on('click', function(ev) {
// options for opening new windows:
// http://w3schools.com/jsref/met_win_open.asp
window.open(this.href,"my_window", "width=400, height=400");
});
$('#link2').on('click', function(ev) {
// Best suited for sending the user somewhere in response to an event
window.location.href = this.href;
});
$('#link3').on('click', function(ev) {
console.log('location href: ', window.location.href);
console.log('location protocol: ', window.location.protocol);
console.log('location hostname: ', window.location.hostname);
console.log('location pathname: ', window.location.pathname);
console.log('location port: ', window.location.port);
console.log('location search: ', window.location.search);
console.log('location hash: ', window.location.hash);
ev.preventDefault(); // Prevent the synacor.com link from working
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment