Results 1 to 7 of 7

Thread: Reading iFrame content from javascript

  1. #1
    MarcelB
    Guest

    Talking Reading iFrame content from javascript

    Hi all,

    Someone typed in some text in an iFrame, and then selected part of that text. Now how can I for instance display the selected part with an alert message?

    I know I can get the whole text with:
    iFramename.document.body.innerHTML


    I also know there is the selection object/property, but I can't seem to get the right combination to be able to get the selected text.

    Any help would be highly appreciated.

  2. #2
    scoutt
    Guest

  3. #3
    MarcelB
    Guest
    Thanx for the input, but it doesn't really, since the example given there selects ALL the text, while I'm searching for some piece of code that lets me do stuff with a selected piece of text from an iFrame, and only the selected text.

  4. #4
    scoutt
    Guest
    well couldn't you take the selected out and use the part where it stores the text to clipboard. other than that I don't think you will be able to do it. because if you search the forum you will see that this question was asked before and that was the answer that I showed you.

  5. #5
    MarcelB
    Guest
    Well, I got it working, and the code for IE 4+ is:


    --------------------------------------------------------------------------------

    var range = myiFrameName.document.selection.createRange();
    var str = range.text;

    alert(str);

    --------------------------------------------------------------------------------


    Now my next question:
    How do I replace the selected text, for instance to put it in bold?

    Stuff like:

    myiFrameName.document.selection.text = '<b>'+str+'</b>'
    or
    myiFrameName.document.selection.innerHTML = '<b>'+str+'</b>'

    doesn't work.


    Any ideas?

  6. #6
    MarcelB
    Guest
    Okay, I got it to work as I wanted..

    Everyone who is curious about how, I found it all at: http://www.webreference.com/js/column12/final.html

    And then specifically the last 4 topics..


    Maybe it's a good idea to post this URL at the other questions about this topic aswell?!

  7. #7
    New Member
    Join Date
    Mar 2009
    Posts
    2

    Re: Reading iFrame content from javascript

    Hi,

    could you please explain how to do this. i refered to the url but still then i am having some confusions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width