Is there any solution on how to determine object's position within DOM structure? Normally I'd use XPath but document.evaluate() is not cross-browser compatible so I'm throwing that off.
Sample page HTML:
<html>
<head></head>
<body>
<div>Some element 1</div>
<div>Some element 2</div>
<div>
<p>some text 1</p>
<img src="#">
<p>some text 2</p>
</div>
</body>
</html>
Now imagine user selects text "text 2" within second paragraph. What I need is to get something like /html/body/div[3]/p[2][.='text 2'] and save it via $.ajax() in database. When user enters the same page again (somewhere in future) I need to highlight text "text 2" again and scroll the second paragraph into view (probably using window.scrollTo()).