[英]javascript open page in new tab with IE8
我正在嘗試在新選項卡中打開一個簡單的鏈接。 我曾嘗試在 google 和 stackoverflow 上搜索,但結果顯示,我們需要更改瀏覽器中的設置。 有沒有辦法使用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>
編寫以下 JavaScript 代碼以打開一個新選項卡
window.open("http://www.targetdomain.com", '_blank');
如果要使用 HTML 來做,請編寫以下代碼:
<a href="http://www.targetdomain.com" target="_blank" rel="noopener noreferrer">Click here to open a new tab</a>
noopener noreferrer
屬性是為了確保新選項卡不會與打開它的選項卡惡意noopener noreferrer
。
你不需要Javascript。
寫就好了
<a href="..." target="_blank">...</a>
此行為取決於特定的瀏覽器設置。 如果 IE 設置設置為 tab-usage,則可以使用它們,除非您指定鏈接應在新窗口中打開。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.