![](/img/trans.png)
[英]How can I use javascript to add svg from illustrator to the DOM at run-time?
[英]How can I get the XUL as a string from a Mozilla add-on at run-time using JavaScript?
我正在嘗試獲取一個窗口的XUL文本作為Javascript中的字符串。 我需要在運行時完成此操作,因為窗口會動態添加/刪除UI元素。
我嘗試了以下方法:
document.toXML()
document.xml
document.documentElement.toXML()
除其他事項外。 沒用! 有人可以幫忙嗎?
您使用XMLSerializer :
new XMLSerializer().serializeToString(document);
我認為沒有函數或字段可以獲取xul文本,但是您可以通過從xul url中讀取內容來解決
function getContentFromURL(url) {
var Cc = Components.classes;
var Ci = Components.interfaces;
var ioService = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
var scriptableStream = Cc['@mozilla.org/scriptableinputstream;1'].getService(Ci.nsIScriptableInputStream);
var channel = ioService.newChannel(url, null, null);
var input = channel.open();
scriptableStream.init(input);
return scriptableStream.read(input.available());
}
因此您可以調用getContentFromURL(document.location)來獲取XUL內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.