A Pen by Andrew Kirchmyer on CodePen.
Created
November 17, 2013 05:25
-
-
Save akirchmyer/7509664 to your computer and use it in GitHub Desktop.
A Pen by Andrew Kirchmyer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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