2009-06-01 5 views
0

Firefoxの拡張機能でJavascriptを使って、新しいタブを開いた。私はwww.google.comや他のリンク(リスト全体)へのリンクをこのタブに書く方法を知らないので、ユーザーがリンクをクリックするとこのページが開きます。Javascript - 新しいタブへのリンクを書き込む

var newTabBrowser2 = gBrowser.getBrowserForTab(gBrowser.selectedTab = gBrowser.addTab()); 
newdocument=newTabBrowser2.contentDocument.documentElement.textContent; 
newdocument.write("<a href=\"http://www.google.com\">google</a><br>"); 
newdocument.write("<a href=\"http://www.yahoo.com\">yahoo</a><br>"); 

を、私はこれを試してみた:残念ながら、これは動作しません

var newTabBrowser2 = gBrowser.getBrowserForTab(gBrowser.selectedTab = gBrowser.addTab()); 

は、これまで私が入力したあなたの助け

いただき、ありがとうございます

var newTabBrowser2 = gBrowser.getBrowserForTab(gBrowser.selectedTab = gBrowser.addTab()); 
newTabBrowser2.contentDocument.documentElement.innerHTML += "<a 

href = \ "http://www.google.com \ "> google
";

しかし、それはデバッガを使用すると動作します。

なぜか?

ありがとうございました

答えて

0

これはあなたが探しているもののようです。

http://mesh.typepad.com/blog/2004/11/creating_a_new_.html

var myUrl = "http://mesh.typepad.com"; 
var tBrowser = document.getElementById("content"); 
var tab = tBrowser.addTab(myUrl); 

これは、それが実行されますたびに新しいタブを作成します - あなたは、このような既存のタブのURLを更新することができます。最後に

var uri = "http://mesh.typepad.com"; 
tBrowser.getBrowserForTab(tab).loadURI(uri); 

は、次のことができるようにすべきであるがフォーカスを新しいタブに設定します。

tBrowser.selectedTab = tab; 
+0

あなたの返信に感謝します 私は、タブにリンクのリスト全体を表示することにもっと関心があり、ユーザはこれらの1つを選択します – Lilz

1

あなたの質問からは、それほど明確ではありません。おそらく次のようなものでしょう:

newwindow=window.open(); 
newdocument=newwindow.document; 
newdocument.write("<a href=\"http://www.google.com\">google</a><br>"); 
newdocument.write("<a href=\"http://www.yahoo.com\">yahoo</a><br>"); 
newdocument.close(); 

???

1

textContentを使用してHTMLコンテンツをドキュメントに追加することはできません.HTMLを使用してHTMLを作成する方がよい場合があります。

どのようにこのような何か(未テスト)について:また

var newTabBrowser2 = gBrowser.getBrowserForTab(gBrowser.selectedTab = gBrowser.addTab()); 
newdocument=newTabBrowser2.contentDocument.documentElement; 

var link=newdocument.createElement("a"); 
link.setAttribute("href", "http://www.google.com"); 
link.textContent="google"; 
newdocument.appendChild(link); 

newdocument.appendChild(newdocument.createElement("br")); 

link=newdocument.createElement("a"); 
link.setAttribute("href", "http://www.yahoo.com"); 
link.textContent="yahoo"; 
newdocument.appendChild(link); 

newdocument.appendChild(newdocument.createElement("br")); 

、それだけで、文書要素のinnerHTMLプロパティに書き込むことも可能です。

関連する問題