Created
May 13, 2012 02:37
-
-
Save sorah/2670692 to your computer and use it in GitHub Desktop.
バックグラウンドでリンクを開くようにする
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>バックグラウンドでリンクを開くようにする</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function () { | |
$('a').click(function (e) { | |
var clickEvent = document.createEvent('MouseEvents'); | |
clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, 0, | |
false, false, false, false, 1, null); | |
$('<a>').attr('href', $(this).attr('href'))[0].dispatchEvent(clickEvent); | |
e.preventDefault(); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<p> | |
<a href="http://example.com">test</a> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment