0

Firefox拡張機能でJavascriptを使用して、新しいタブを開きました。www.google.comへのリンクと他のリンク(リスト全体)をこのタブに書き込む方法がわかりません。ユーザーがリンクをクリックすると、このページが開きます。

ご協力ありがとうございました

これまでに入力しました:

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

残念ながら、これは機能しません。

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());
newTabBrowser2.contentDocument.documentElement.innerHTML += "<a 

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

しかし、それは私がデバッガーを使用するときにのみ機能します

なぜですか?

ありがとう

4

3 に答える 3

1

ドキュメントに HTML コンテンツを追加するために textContent を使用できるとは思えません。おそらく、DOM を使用して 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 に書き込むこともできます。

于 2009-06-01T12:41:33.840 に答える
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();

???

于 2009-06-01T12:11:37.457 に答える
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;
于 2009-06-01T11:51:33.567 に答える