Javascript retrieve absolute XPATH via ID of Node -
hello trying retrieve xpath of document via id of node, saw simple matter when looking @ code simple:
//iframe[@id=key];
but won't work, i've tried every combination of syntax can think of , not luck, print out "undefined". code
function getnode(htmlurl, filename, xpath, callback){ var key = filename+xpath; var frame = document.getelementbyid(key); frame.addeventlistener("load", function(evt){ var value= frame.contentdocument.evaluate(xpath, frame.contentdocument, null,9,null); if(value!=null){ callback(value); } }, false); frame.contentwindow.location.href = htmlurl; } function init(htmlurl, filename, xpath){ getnode(htmlurl, filename, xpath, function(node) { console.debug(node.outerhtml); }); }
am trying xpath inside iframe, thought i'd have point xpath iframe first
if want find element inside of iframe need use evaluate method on document in iframe e.g.
frame.contentdocument.evaluate(xpath, frame.contentdocument, null,9,null)
but if set src load html document don't expect able access nodes in document in code setting src, instead set onload event handler wait until document has been loaded. in event handler can access nodes in loaded document.
Comments
Post a Comment