Created
February 2, 2010 23:40
-
-
Save navarr/293176 to your computer and use it in GitHub Desktop.
Open a Link in a New Tab using JavaScript
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
function newTab(url) | |
{ | |
if(url.href) { url = url.href } // so that you can use onclick="return newTab(this);" | |
form = document.createElement("form"); | |
form.setAttribute("method","get"); | |
form.setAttribute("target","_blank"); | |
form.setAttribute("action",url); | |
form.submit(); | |
return false; | |
} |
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
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> | |
<head> | |
<title>New Tab</title> | |
<script type="text/javascript" src="newTab.js"></script> | |
</head> | |
<body> | |
<a href="http://www.google.com/" onclick="return newTab(this);">Google (in a new tab!)</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment