Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Text from Xpath and Highlight it
    primarykey
    data
    text
    <p>I am trying to build a E pub Reader. I am able to highlight the user selected text and i am getting the x path of that particular selected text. After that i am trying to build a function which takes x path as parameter and show the user selected text by changing background color. but its not working. </p> <p>Code:-</p> <pre><code>function uiWebview_restoreSelection() { var selectionDetails = "/HTML[1]/BODY[1]/DIV[1]/text()[1]|910|/HTML[1]/BODY[1]/DIV[1]/text()[1]|930"; //alert("selectionDetails"+selectionDetails); if (selectionDetails != null) { selectionDetails = selectionDetails.split(/\|/g); alert("selectionDetails" + selectionDetails); if (typeof window.getSelection != 'undefined') { var selection = window.getSelection(); selection.removeAllRanges(); var range = document.createRange(); var selectionDetails0 = selectionDetails[0]; alert("selectionDetails0" + selectionDetails0); selectionDetails0 = selectionDetails0.replace(/\//g, "/h:"); selectionDetails0 = selectionDetails0.replace("h:t", "t"); alert("selectionDetails0" + selectionDetails0); var selectionDetails2 = selectionDetails[2]; alert("selectionDetails2" + selectionDetails2); selectionDetails2 = selectionDetails2.replace(/\//g, "/h:"); selectionDetails2 = selectionDetails2.replace("h:t", "t"); alert("selectionDetails2" + selectionDetails2); range.setStart(document.evaluate(selectionDetails0, document, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue, Number(selectionDetails[1])); range.setEnd(document.evaluate(selectionDetails2, document, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue, Number(selectionDetails[3])); document.designMode = "on"; var newSpanMark = document.createElement("span"); document.execCommand("HiliteColor", false, "red"); range.insertNode(newSpanMark); document.designMode = "off"; } } } </code></pre> <p>Please suggest for the above problem.</p> <p>Thanks in Advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload