Skip to content

Instantly share code, notes, and snippets.

@sorah
Created May 13, 2012 02:37
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 sorah/2670692 to your computer and use it in GitHub Desktop.
Save sorah/2670692 to your computer and use it in GitHub Desktop.
バックグラウンドでリンクを開くようにする
<!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