![](/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.