Reputation: 607
I'm currently working on a little html/js site and my current goal is to load a .txt file into a page (accomplished this with iFrame src), then transfer the text from the iFrame to a textArea. The latter I cannot do for some reason. I have tried to get various scripts to help me but none of them seem to work.
Currently lets imagine i have only this in the html:
<iframe name=my_frame id=my_frame src=textfile.txt height=100% width=100% frameborder=0 scrolling=auto marginheight=5 marginwidth=5></iframe>
The java code i am using to validate whether I am getting the inner text of the iFrame is a simple alert:
<script>
alert($('my_frame').*[attribute]*);
</script>
The ''attribute'' part is a dummy in this case. I've used things like HTML, innerHTML, innerTEXT, text, value, body, instead - but none of them work....
Perhaps someone here could assist with a little script to accomplish moving plain text from iFRAME to textArea, or even suggest a better way of approaching this?
I would be extremely grateful for any and all assistance.
Cpt.Mgn.
Upvotes: 1
Views: 1866
Reputation: 8337
if your file is hosted and the textfile is public-ally accessible, then you can try this
$.get("http://yourdomain.com/a.txt", null, function(response){
$("#theTextArea").val(response); // where theTextArea is the ID of the textarea you want to put the data into.
});
Upvotes: 0
Reputation: 393
I think you must change your code:
<script>
alert($('#my_frame').html());
</script>
# Is a selector for id.
html() return all the html inside the element.
I hope this helps :)
EDIT:
<iframe name=my_frame id=my_frame src=textfile.txt height=100% width=100% frameborder=0 scrolling=auto marginheight=5 marginwidth=5>Hello </iframe>
And alert said: Hello
Link to code: http://jsfiddle.net/rEM6H/
Upvotes: 2