0

My Iframe looks like this

<iframe id="myId" class="af_richTextEditor_content-input" frameborder="0" style="height:     36em;" src="/blank.html">
    <html>
        <head>
            <title></title>
        </head>
        <body dir="ltr" style="margin: 0px; padding: 1px; font-size: small; font-family: Tahoma,Verdana,Arial,Helvetica,FreeSans,sans-serif; -moz-box-sizing: border-box;">
            myText
            <br>
            MySecondText
        </body>
    </html>
</iframe>

This iframe behaves like textarea (it is like input field) and I can write text into it and select some text inside. Now When button is pressed I want to get selected area (start position and end position of body tag selection). How to? JQuery? Pure JS? Examples?

zmeda
  • 2,909
  • 9
  • 36
  • 56
  • Duplicate: http://stackoverflow.com/questions/1471759/how-to-get-selected-text-from-iframe-with-javascript – Some Guy Nov 07 '11 at 08:25

1 Answers1

0

If you just want the selected text as the question title suggests, my answer here will do the job (but only for iframes that come from the same domain as the containing document):

how to get selected text from iframe with javascript?

If you're looking for character offsets within the <body>, as the question body suggests, here's how you can do that:

Get a range's start and end offset's relative to its parent container

Community
  • 1
  • 1
Tim Down
  • 318,141
  • 75
  • 454
  • 536