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? :(" );
}
}


Sign In
Create Account

Back to top









