Kanwal Gill Kanwal Gill - 1 day ago 4
Javascript Question

is it possible to put iframe value in textarea?

I have seen in some websites, such as Wordpress, that they have rich text editors with a toggle option with which you can see html code of what you are typing. Is there any way I can see the src of an iframe in a textarea?

<textarea name="textarea" id="textarea"></textarea>
<iframe name="editor"style="width:600px;height:500px"id="iframe"></iframe>
<input type ="button"id="btn"value="btn"/>

<script>
editor.document.designMode='on';
$("#btn").click(function(){
$("#textarea").val($("#iframe").val());
})
</script>

Answer

You can do this with an ajax $.get request

$("#btn").click(function(){
    var iframe_url = $("#iframe").attr('src');

    $("#textarea").val( 'loading...' );

    $.get( iframe_url, {}, function(response){
        $("#textarea").val( response );
    } );
});
Comments