2015-11-05 84 views
0
<ul class="test"> 
    <li> 
     <a href="abc.com">abc.com</a> 
     <a href="xyz.com">xyz.com</a> 
    </li> 
</ul> 

如何在頁面加載時在新窗口中打開URL上方的URL。在頁面加載時在新窗口中打開URLS

+0

您的意思是當你用這個html打開頁面時,它會打開其他窗口而不點擊任何東西? – Dhunt

+0

@Dhunt:是的,它會打開,沒有點擊鏈接。 – harry

回答

0
**I got the solution: Thanks to everyone for your help.** 

<ul class="test"> 
    <li> 
     <a href="abc.com">abc.com</a> 
     <a href="xyz.com">xyz.com</a> 
    </li> 
</ul> 

<script type='text/javascript' > 
    $(document).ready(function(){ 
     $(".test li a").each(function(){ 
      url = $(this).attr("href"); 
      window.open(url,'_blank') 
     }); 
    }) 
</script> 
1

給了一個標籤target="_blank"

<ul class="test"> 
    <li> 
     <a href="abc.com" target="_blank">abc.com</a> 
     <a href="xyz.com" target="_blank">xyz.com</a> 
    </li> 
</ul> 
+0

**在頁面加載**?你錯過了嗎? – Rayon

+0

使用''其中myFunction()是您的js函數,可以完成您的任務。在這個例子中打開你的鏈接。或者你不知道如何寫js?我認爲它不足以指定 –

+0

'target =「_ blank」'不是指定問題的解決方案! – Rayon

1

使用特定的選擇選擇a元素,並使用window.open這些元素的href屬性

$('a').each(function() { 
    window.open(this.href); 
}); 
0

你有添加target="_blank"

<a href="abc.com" target="_blank">abc.com</a> 
<a href="xyz.com" target="_blank">xyz.com</a> 
相關問題