A workaround for deep binding using Xpath Links

Prior to Firefox 5 Firefox supports XPath links like #xpath: / html / body / div [3], which can be used in conjunction with a bookmarklet like http://antimatter15.com/wp/2009/11/xpath-bookmark -bookmarklet / for linking in HTML documents missing the correct IDs. This feature has been removed as part of code cleanup at https://bugzilla.mozilla.org/show_bug.cgi?id=457102

I often want to link to web pages that have good content but don't have the correct IDs. So if the page is very long and I want to link to part of it. I can not do it. Firefox supported Xpath links, but now they removed it. Does anyone know how to overcome this problem.

+3


source to share


1 answer


You can still use XPaths in document.evaluate

// get node
var xpr = document.evaluate('/html/body/div[3]', document, null, XPathResult.ANY_TYPE, null),
    elm = xpr.iterateNext();

      



Then you can use elm.scrollIntoView

(won't work in IE, see compatibility)

elm.scrollIntoView();

      

0


source







All Articles