我想在新选项卡中打开一个简单的链接。我试图搜索谷歌和stackoverflow,但结果表示,我们需要更改浏览器中的设置。有没有办法使用JavaScript做同样的事情?与IE8的新标签中的JavaScript打开页面
下面是示例脚本
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function gotoNewtab(){
document.forms[0].target="_blank";
document.forms[0].method = "post";
document.forms[0].action = "http://www.google.com";
document.forms[0].submit();
}
</script>
</head>
<body>
<form name="frm">
<p> click the below link to open the page in new tab </p>
<p> <a href="##"
onclick="javaScript:return gotoNewtab();">
click here </a>
</p>
</form>
</body>
</html>
您可以要求结果不会取代当前页面,而是会打开一个新标签还是新窗口取决于浏览器设置。 – Neil