From: Aaron Gray on 10 Nov 2005 12:08 <iframe name="iframe" width="100%" height="25%" src="test1.txt"> </iframe> <a href="test1.txt" target="input">one</a> <a href="test2.txt" target="input">two</a> <form name="form1"> <textarea name="textarea" cols=80 rows=18> This is a test </textarea><br> <button name="Copy" value="Copy" OnClick="DoCopy()">Copy</button> </form> <script> function DoCopy() { form1.textarea.value=iframe.innerText; } </script>
From: Aaron Gray on 10 Nov 2005 12:10 Whoops, forgot the question ! I want to copy the text from a text document opened in an iframe into a textarea at th press of a button. > <iframe name="iframe" width="100%" height="25%" src="test1.txt"> > </iframe> > > <a href="test1.txt" target="input">one</a> > <a href="test2.txt" target="input">two</a> > > <form name="form1"> > <textarea name="textarea" cols=80 rows=18> > This is a test > </textarea><br> > <button name="Copy" value="Copy" OnClick="DoCopy()">Copy</button> > </form> > > <script> > > function DoCopy() > { > form1.textarea.value=iframe.innerText; > } > </script> I tried 'iframe.body.innerText' but that did not work. Aaron
From: VK on 10 Nov 2005 12:25 Aaron Gray wrote: > Whoops, forgot the question ! > > I want to copy the text from a text document opened in an iframe into a > textarea at th press of a button. > > > <iframe name="iframe" width="100%" height="25%" src="test1.txt"> > > </iframe> > > > > <a href="test1.txt" target="input">one</a> > > <a href="test2.txt" target="input">two</a> > > > > <form name="form1"> > > <textarea name="textarea" cols=80 rows=18> > > This is a test > > </textarea><br> > > <button name="Copy" value="Copy" OnClick="DoCopy()">Copy</button> > > </form> > > > > <script> > > > > function DoCopy() > > { > > form1.textarea.value=iframe.innerText; > > } > > </script> > > I tried 'iframe.body.innerText' but that did not work. > > Aaron <iframe name="iframe01" width="100%" height="25%" src="test1.txt"> </iframe> <form name="form1"> <textarea name="txt01" cols=80 rows=18> This is a test </textarea><br> <button name="Copy" value="Copy" OnClick="DoCopy()">Copy</button> </form> <script> function DoCopy() { document.forms['form1'].elements['txt01'].value = document.frames['iframe01'].document.body.innerHTML; } </script> 1) Never ever give the names/id using generic html element names ("iframe", "textarea" etc.) 2) <http://www.javascripttoolbox.com/bestpractices/> see about addressing frames/form elements - helps a lot. ;-)
From: Aaron Gray on 10 Nov 2005 12:29 > 1) Never ever give the names/id using generic html element names > ("iframe", "textarea" etc.) Okay :) > 2) <http://www.javascripttoolbox.com/bestpractices/> see about > addressing frames/form elements - helps a lot. This does not deal with getting the text from a text document in an iframe which is what I was after. Aaron
From: Martin Honnen on 10 Nov 2005 14:42 Aaron Gray wrote: > <iframe name="iframe" width="100%" height="25%" src="test1.txt"> > </iframe> Is that really a text/plain document in the iframe? Or a text/html document? Obviously the DOM is defined for (structured) HTML and XML documents but not for (unstructured) text documents. Though some browser (IE, Mozilla too perhaps) might expose a document with a body for text, see below. > <form name="form1"> > <textarea name="textarea" cols=80 rows=18> > This is a test > </textarea><br> > <button name="Copy" value="Copy" OnClick="DoCopy()">Copy</button> <input type="button" value="Copy" onclick="DoCopy(this.form.elements.textarea, 'iframe')"> > function DoCopy() function DoCopy (textControl, iframeName) { if (window.frames && window.frames[iframeName] && window.frames[iframeName].document && window.frames[iframeName].document.body && window.frames[iframeName].document.body.innerHTML) { textControl.value = window.frames[iframeName].document.body.innerHTML; } } -- Martin Honnen http://JavaScript.FAQTs.com/
|
Next
|
Last
Pages: 1 2 3 4 Prev: How to call a js file from another js file? Next: How to rotate the image |