Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
バックグラウンドでリンクを開くようにする
<!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
You can’t perform that action at this time.