Jump to content

Firefox Extension JavaScript help needed.

- - - - -

  • Please log in to reply
No replies to this topic

#1
Andreilp

Andreilp

    Newbie

  • Members
  • Pip
  • 6 posts
Hei guys, i'm trying to develop a firefox extension and i want to use this code here: https://developer.mo...ts/On_page_load for intercepting the page loading and doing some stuff with it afterwards.

I want to use the evaluate method, to compare an XPath to the current page and see if it finds the node, but i don't know how to do this. I've tried doc.evaluate(....) but it doesn't work. I've tried a lot of variations, but it gives an error at that line (how i know this is that it displays the alert "1" but not the "2" ). So what's the correct syntax for this? doc.??what??.evaluate(....) ? If any1 knows.


window.addEventListener("load", function() { myExtension.init(); }, false);


var myExtension =

{

  init: function()

  {

    var appcontent = document.getElementById("appcontent");   // browser

    if(appcontent)

      appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);

    var messagepane = document.getElementById("messagepane"); // mail

    if(messagepane)

      messagepane.addEventListener("load", function(event) { myExtension.onPageLoad(event); }, true);

  },


  onPageLoad: function(aEvent)

  {

    //********************************************* CODE I'M REFERRING TO IN THE POST (start)

    var doc = aEvent.originalTarget; // doc is document that triggered "onload" event


    window.alert( "1" );

    var nodesFound = doc.evaluate("/html/body/div[2]/center/span/center/div[1]/div/div", doc.defaultView, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

    window.alert( "2" );

    if ( nodesFound )

    {

      window.alert( "YEY XPATH !!" );

    }

    else

    {

      window.alert( "BUU XPATH" );

    }

    //********************************************* CODE I'M REFERRING TO IN THE POST (end)


    // add event listener for page unload

    aEvent.originalTarget.defaultView.addEventListener("unload", function(event){ myExtension.onPageUnload(event); }, true);

  },


  onPageUnload: function(aEvent)

  {

    // do something

    //window.alert( "Leaving so soon? :(" );

  }

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users