[英]Display a page with a Firefox extension
有人可以告訴我如何編寫一個 Firefox 擴展,當用戶打開一個新選項卡或 web 頁面時,它會顯示一個本地 HTML 頁面(包含在擴展中)。
您將需要這個 function 來讀取插件中的文件
function Read(file)
{
var ioService=Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var scriptableStream=Components
.classes["@mozilla.org/scriptableinputstream;1"]
.getService(Components.interfaces.nsIScriptableInputStream);
var channel=ioService.newChannel(file,null,null);
var input=channel.open();
scriptableStream.init(input);
var str=scriptableStream.read(input.available());
scriptableStream.close();
input.close();
return str;
}
然后創建一個元素並添加 HTML 的內容。
gBrowser.addEventListener("DOMContentLoaded", function(e) {
var documentElement = e.originalTarget.defaultView.document;
var div = documentElement.createElement("div");
div.innerHTML = Read("chrome://extensioname/content/file.html");
documentElement.body.appendChild(div);
});
使用e.originalTarget.defaultView.location.href
過濾您想要此行為的頁面。
You may find some info at https://developer.mozilla.org/en/Observer_Notifications and https://developer.mozilla.org/en/Code_snippets/Progress_Listeners and https://developer.mozilla.org/En/Code_snippets/ On_page_load 。
要在 XUL 內容中顯示 HTML 內容(盡管您也可以打開純 XHTML 對話框),您可以使用XUL iframe
如果你覆蓋BrowserOpenTab
function 你可以讓它打開你選擇的頁面而不是about:blank
。 這可能是您的擴展程序提供的頁面; 理想情況下,您將為它實現一個關於 URI 的替代方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.