Results 1 to 3 of 3

Thread: How to select iFrame contents?

  1. #1
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to select iFrame contents?

    I am trying to make a JavaScript highlight the contents of an iFrame. It is easy enough when I use a textarea, but I can't seem to get it to work in an iFrame.


    My frame id is "external". The following seems to reference my iFrame, but it doesn't select the contents, it just moves the page so the iFrame is all in the page (focused?).

    javascript:"document.all.external.focus();document.all.external.select()"

  2. #2
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Same problem, have you found the solution??

    Hi Tali,

    I have exactly the same problem...

    but i think im near to find the solution, because the "focus" is already working... now we just need to find the correct command to select all and copy...

    <html><head><title>JavaScript code/Clipboard</title>
    <script language="JavaScript"><!--


    function SelecionarTexto(){
    document.form1.textarea1.focus();
    document.form1.textarea1.select();
    }

    --></script></head>
    <body>




    <IFRAME SRC="http://www.google.com.br" WIDTH="100%" HEIGHT="60" onload="focus();">
    <!-- Alternate content for non-supporting browsers -->
    </IFRAME>


    <input type='button'onClick="SelecionarTexto()">

    <form name="form1">
    <textarea cols="60" rows="8" name="textarea1">
    This is the textarea content. Change it to suit...
    </textarea>
    </form>
    </body></html>
    Last edited by jpcarusi; 03-26-2005 at 03:30 PM.

  3. #3
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Are you trying to select a textarea within the iframe, or the entire page? The later would be more difficult. If the former though, something like the below should work:

    Code:
    var myiframe=document.getElementById("aiframe")
    if (myiframe.contentDocument) //ns6 syntax
    myiframe.contentDocument.myform.mytextarea.select()
    else if (myiframe.Document) //ie5+ syntax
    myiframe.Document.myform.mytextarea.select()
    where "aiframe" is the ID of your iframe, and "myform" and "mytextarea", the name of your form and textarea.

Bookmarks

Posting Permissions

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