View Full Version : How to select iFrame contents?

03-08-2005, 08:48 AM
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?).


03-26-2005, 03:26 PM
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(){


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

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

<form name="form1">
<textarea cols="60" rows="8" name="textarea1">
This is the textarea content. Change it to suit...

03-26-2005, 05:44 PM
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:

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