2

i want to copy image from an iframe to div ot to textarea like this jsfiddle.net/purmou/xEtL9/

<textarea rows="10" cols="40" id="content">
</textarea>

<div id="fake">
    <iframe width="100%" height="400px" src="http://www.w3schools.com/"></iframe>
</div>

And

     $(function(){
            $("#fake iframe").click(function(){
                var update = $("<div>").append(
                    $("<iframe>").attr("src", $(this).attr("src"))
                ).html();

                $("#content").val(function( i, v ) {
                    return v + update;
                });
            });
        });

But for iframe it is not working..Any suggestion??

SHAURAJ SINGH
  • 517
  • 7
  • 20
  • is this image your are trying to copy in content reside inside the iframe? if yes and ur domain is same you mentioned than i think its not possible..because this iframe is on another domain..see this post [Post](http://stackoverflow.com/questions/5539756/how-can-i-pass-value-to-iframe-with-javascript) – Tami May 22 '12 at 11:22
  • "I don't think you can modify the HTML in an iframe from a different domain. " - not the same thing. you can read it fine. – jenson-button-event May 22 '12 at 11:33

2 Answers2

0

This to do with the iframe not supporting onclick directly.

Discussed here: Adding click event handler to iframe

Basically it says you need to subscribe to the event via a listener to the iframe's document object:

You can use closures to pass parameters:

iframe.document.addEventListener('click', function(event) {clic(this.id);}, false)
Community
  • 1
  • 1
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
0

You have not given id to your IFrame and have to use the IFrame id instead of <IFrame> tag.

Check below code

<iframe id="iframe1" width="100%" height="400px" src="http://www.w3schools.com/"/>

& $("iframe1").attr("src", $(this).attr("src"))

Happy coding!!!

Ravi Vanapalli
  • 9,805
  • 3
  • 33
  • 43