[英]How to open new window with multiple tabs with javascript?
我想在打開多個選項卡的新窗口中打開一個鏈接。 目前,我可以在同一個窗口中打開多個選項卡; 這看起來像:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('http://yahoo.com');
window.open('http://google.com');
因此,單擊“您的鏈接”類的鏈接將在同一窗口中打開多個鏈接。 為了做同樣的事情,但在一個新的普通窗口中,我嘗試在第一個window.open
使用以下 jquery 參數window.open('url', 'window name', 'window settings')
。 然而,這只會在新窗口中打開一個鏈接,而且格式也不理想。
你可以做到這一點,通過這樣做:
假設您當前的文件是index.html
。
第 1 步:在index.html
文件夾中創建一個新文件。 (假設temp.html
)。
第 2 步:現在在 JavaScript 代碼index.html
,寫入:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('./temp.html', '_blank', 'location=yes,scrollbars=yes,status=yes');
});
這將打開一個新窗口。
第 3 步:只需在temp.html
添加script
標簽,並在temp.html
編寫以下代碼:
var links = ['http://yahoo.com', 'http://google.com'];
for(let i = 0 ; i < links.length ; i++){
window.open(links[i]);
}
window.close();
在數組中,放入所有要打開的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.