Monday, 15 August 2011

javascript - Getting already selected text -



javascript - Getting already selected text -

by using next code getting selected text's startindex , selected text itself. storing them in local database. changing selected text background color yellow.

var maindiv = document.getelementsbytagname("body")[0]; var sel = getselectioncharoffsetswithin(maindiv); var selectedtext = window.getselection(); location.href = selectedtext + '*' + sel.start; // phone call ios function. var range = window.getselection().getrangeat(0); var span = document.createelement("span"); span.style.backgroundcolor = "yellow"; span.setattribute("id", sel.start); range.surroundcontents(span);

now, doing else, , 1 time again come same page. here want show selected text highlighted.

use rangy , nil beats , trying

rangy

have @ demo

javascript jquery

No comments:

Post a Comment