我想讓標簽同時打開兩個 URL。這是我嘗試過的:
只有 HTML
<a href="URL1" target="_blank" onclick="window.open('URL2');">text</a>
這確實有效,但不是我想要的方式。單擊它時它會打開 URL2,如果在新選項卡中通過右鍵單擊或滑鼠滾輪打開它會打開 URL1。我希望它同時在新標簽頁中打開兩個頁面。
HTML JavaScript HTML:
<a id="myId">text</a>
JS:
myId.onclick = function(){
open('https://www.example1.com');
location.href = ('https://www.example2.com');
}
這根本不起作用。
uj5u.com熱心網友回復:
這是你的代碼:
myId.onclick = function(){`enter code here`
open('https://www.example1.com');
location.href = ('https://www.example2.com',,'_blank');
}
將代碼更改為:
myId.onclick = function(){
window.open('https://www.example1.com','_blank'); //just use window.open() for both the cases;
window.open('https://www.example2.com');
}
希望,您已經找到了解決問題的方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/371870.html
標籤:javascript html 锚
