過去には、これは機能していました:
// writing
var newTab = window.open();
newTab.document.write("<html><head><title>I'm just a tab</title></head>");
newTab.document.write("<body id='hello'>With some text on it</body>");
newTab.document.write("</html>");
newTab.document.close();
// reading what was wrote
newTab.document.getElementById('hello').addEventListener("click", custom_search_function(), false);
ただし、このコードを実行しようとすると、Firefox でセキュリティ エラーが表示されます。
Error: SecurityError: The operation is insecure.
フォーラムで代替案を検索しましたが、これは機能します:
var textOnPage = "<html><head><title>I'm just a tab</title></head><body>";
var newTab = window.open("data:text/html;charset=UTF-8," + encodeURIComponent(textOnPage));
newTab.document.close();
しかし、私は経由でページにアクセスできませんgetElementById
newTab.document.getElementById('hello').addEventListener("click", custom_search_function(), false);
戻り値:
Error: TypeError: newTab.document.getElementById(...) is null
この新しいタブに書き込んでから、次のような関数を使用して戻って読み取るにはどうすればよいgetElementById
ですか?