2012-02-16 119 views
0

我很遺憾地看到,在我正在進行的Google chrome擴展程序中,當我的博客的有效鏈接實際上並未在瀏覽器中打開頁面以查看頁面時。我的popup.html文件包含標準<a href="http://sample.com">Sample</a>。我想知道是否有腳本或需要在您的Google Chrome瀏覽器擴展程序彈出窗口中插入有效的網頁加載鏈接。在谷歌瀏覽器擴展中鏈接到網頁?

+2

這應該工作,但嘗試''Sample感謝 – abraham 2012-02-16 22:41:25

回答

4

有兩種常見的方法:

<a href="http://sample.com" target="_blank">Sample</a> 

或者(如果你想有更多的控制):

<a href="http://sample.com">Sample</a> 

<script> 
window.onload = function(){ 
    var links = document.getElementsByTagName('a'); 
    for(var i = 0; i < links.length; i++){ 
     links[i].addEventListener('click', function(){ 
      chrome.tabs.create({'url': this.getAttribute('href')}, function(tab) { 
       // tab opened 
      }); 
     }); 
    } 
} 
</script> 
+0

,它沒有工作起初,但後來我發現我在鏈接本身有錯誤。 :-P – beakr 2012-02-17 02:14:29