我想在新選項卡中打開一個簡單的鏈接。我試圖搜索谷歌和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