不工作的Firefox code显示用户的书签 [英] Firefox code displaying user bookmarks not working

查看:138
本文介绍了不工作的Firefox code显示用户的书签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一些code在Firefox扩展,显示用户的书签,但它不工作(文本一些文本出现在页面上,但不是书签),没有人知道为什么吗?

在code:

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0 Strict标准// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-strict.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtmlXML:LANG =FR>
< HEAD>
   <标题> /标题>页面,当用户打开一个新的标签或窗口&LT显示;
   < META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= ISO-8859-1/>   <脚本类型=文/ JavaScript的>       功能的init(){
         VAR historyService = Components.classes [@ mozilla.org/browser/nav-history-service;1]
                                     .getService(Components.interfaces.nsINavHistoryService);
         VAR的选择= historyService.getNewQueryOptions();
         变种查询= historyService.getNewQuery();         VAR bookmarksService = Components.classes [@ mozilla.org/browser/nav-bookmarks-service;1]
                                         .getService(Components.interfaces.nsINavBookmarksService);
         VAR toolbarFolder = bookmarksService.toolbarFolder;         query.setFolders([toolbarFolder],1);         VAR的结果= historyService.executeQuery(查询选项);
         VAR rootNode中= result.root;
         rootNode.containerOpen =真;         //遍历这个文件夹的直接子和转储到控制台
         output.innerHTML + ='测试';         对于(VAR I = 0; I< rootNode.childCount;我++){
           变种节点= rootNode.getChild(ⅰ);
             output.innerHTML + ='测试'; //不工作
             output.innerHTML + =(孩子:+ node.title +\\ n); //不工作
            //转储(孩子:+ node.title +\\ n);不工作
         }         //使用后关闭容器!
         rootNode.containerOpen = FALSE
         }   < / SCRIPT>
< /头>
       <身体的onload =的init()>
          < P>有的文字< P>
          < D​​IV ID =输出>
          < / DIV>
       < /身体GT;
< / HTML>


解决方案

添加code将覆盖文件,它的作品! (看到整个扩展 Firefox扩展不工作。

code:

 函数read(文件)
{
   VAR的IOService = Components.classes [@ mozilla.org/network/io-service;1]
       .getService(Components.interfaces.nsIIOService);
   VAR scriptableStream =组件
       .classes [@ mozilla.org/scriptableinputstream;1]
       .getService(Components.interfaces.nsIScriptableInputStream);   VAR渠道= ioService.newChannel(文件,NULL,NULL);
   无功输入= channel.open();
   scriptableStream.init(输入);
   无功海峡= scriptableStream.read(input.available());
   scriptableStream.close();
   input.close();
   返回海峡;
}gBrowser.addEventListener(DOMContentLoaded功能(E){
    VAR documentElement = e.originalTarget.defaultView.document;
    VAR的div = documentElement.createElement(分区);
    div.innerHTML =读(铬://firefox_extension/content/locale.html);
    VAR historyService = Components.classes [@ mozilla.org/browser/nav-history-service;1]
                                   .getService(Components.interfaces.nsINavHistoryService);
    VAR的选择= historyService.getNewQueryOptions();
    变种查询= historyService.getNewQuery();    VAR bookmarksService = Components.classes [@ mozilla.org/browser/nav-bookmarks-service;1]
                                     .getService(Components.interfaces.nsINavBookmarksService);
    VAR toolbarFolder = bookmarksService.toolbarFolder;    query.setFolders([toolbarFolder],1);    VAR的结果= historyService.executeQuery(查询选项);
    VAR rootNode中= result.root;
    rootNode.containerOpen =真;    //遍历这个文件夹的直接子和转储到控制台
    对于(VAR I = 0; I< rootNode.childCount;我++){
       变种节点= rootNode.getChild(ⅰ);
       变量$ I = documentElement.createElement(分区);
       $ i.innerHTML + =(孩子:+ node.title +\\ n);
       documentElement.body.appendChild($ I);
     }    //使用后关闭容器!
    rootNode.containerOpen = FALSE;    documentElement.body.appendChild(DIV);
},假);

I'm using some code in a Firefox extension to display the bookmarks of an user but it's not working (the text "some text" appears on the page but not the bookmarks), does someone know why ?

the code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
   <title>Page displayed when a user opens a new tab or window</title>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

   <script type="text/javascript">

       function init() {
         var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
                                     .getService(Components.interfaces.nsINavHistoryService);
         var options = historyService.getNewQueryOptions();
         var query = historyService.getNewQuery();

         var bookmarksService = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
                                         .getService(Components.interfaces.nsINavBookmarksService);
         var toolbarFolder = bookmarksService.toolbarFolder;

         query.setFolders([toolbarFolder], 1);

         var result = historyService.executeQuery(query, options);
         var rootNode = result.root;
         rootNode.containerOpen = true;

         // iterate over the immediate children of this folder and dump to console
         output.innerHTML+='test';

         for (var i = 0; i < rootNode.childCount; i ++) {
           var node = rootNode.getChild(i);
             output.innerHTML+='test'; // not working
             output.innerHTML+=("Child: " + node.title + "\n"); //not working
            //dump("Child: " + node.title + "\n"); not working
         }

         // close a container after using it!
         rootNode.containerOpen = false
         }

   </script>
</head>
       <body onload="init()">
          <p>Some text<p>
          <div id="output">
          </div>
       </body>
</html>

解决方案

Adding the code to the overlay file, it works ! (to see the entire extension Firefox extension not working.)

code :

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;
}

gBrowser.addEventListener("DOMContentLoaded", function(e) {
    var documentElement = e.originalTarget.defaultView.document;
    var div = documentElement.createElement("div");
    div.innerHTML = Read("chrome://firefox_extension/content/locale.html");


    var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
                                   .getService(Components.interfaces.nsINavHistoryService);
    var options = historyService.getNewQueryOptions();
    var query = historyService.getNewQuery();

    var bookmarksService = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
                                     .getService(Components.interfaces.nsINavBookmarksService);
    var toolbarFolder = bookmarksService.toolbarFolder;

    query.setFolders([toolbarFolder], 1);

    var result = historyService.executeQuery(query, options);
    var rootNode = result.root;
    rootNode.containerOpen = true;

    // iterate over the immediate children of this folder and dump to console
    for (var i = 0; i < rootNode.childCount; i ++) {
       var node = rootNode.getChild(i);
       var $i = documentElement.createElement("div");
       $i.innerHTML+=("Child: " + node.title + "\n");
       documentElement.body.appendChild($i);
     }

    // close a container after using it!
    rootNode.containerOpen = false;

    documentElement.body.appendChild(div);
},

false

);

这篇关于不工作的Firefox code显示用户的书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆