尝试这个:
<a href="javascript:goto()">Hello</a>
function goto() {
/* Some code to be executed */
window.open("http://www.google.com");
}
如果您想在鼠标右键单击时在新选项卡中打开,
<a href="http://www.google.com">Hello</a>
点击鼠标右键并在新标签页中打开
或者
你可以试试这个:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="jquery.min.js"></script>
<script>
function goto() {
window.location = "http://www.google.com";
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementsByTagName('a')[0].addEventListener('contextmenu', function (ev) {
ev.stopPropagation();
ev.preventDefault();
goto();
});
document.getElementsByTagName('a')[0].addEventListener('click', function (ev) {
goto();
});
}, false)
</script>
</head>
<body>
<a href="#">Hello</a>
</body>
</html>