Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select substring in html element
#2
Tested only with IE 9.
May fail with some pages/elements/arguments.

Member function Htm.SelectText
Code:
Copy      Help
function [iStart] [iLength]

;Selects text of this element.
;Error if fails.

;iStart - selection start offset.
;iLength - selection length. If omitted or 0, selects all to the end. If negative, selection will be empty.


MSHTML.IHTMLTxtRange r
MSHTML.IHTMLBodyElement b
MSHTML.IHTMLTextAreaElement ta
MSHTML.IHTMLInputElement in

_s=el.tagName
sel _s 1
,case "BODY" b=+el; r=b.createTextRange
,case "TEXTAREA" ta=+el; r=ta.createTextRange
,case "INPUT" in=+el; r=in.createTextRange; err ;;only for type=text. Fails if moveToElementText.

if !r
,b=el.document.body
,r=b.createTextRange
,r.moveToElementText(el)

if(iStart) r.moveStart("character" iStart)
if(iLength) r.collapse(TRUE); if(iLength>0) r.moveEnd("character" iLength)

r.select

err+ end _error


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)