简体   繁体   中英

setting textarea val after load web in iframe

I have loaded a web page using jquery into an iframe

$("#frame").attr("src", "website"); //this website is **external** web!

and I want to set value of textarea inside this iframe for example when clicking

$( "body" ).on( "click", "#button", function() {
    document.getElementById('textareaID').value = 'new value';
    $('textarea#textareaID').val('new value');
});

it does not work in both ways any ideas?

给该框架命名,并以window.frames [“ framename”]。document.getElementById(“ textareaID”)。value =“ new value”;的形式访问该框架中的元素。

You can use the jquery contents() and find() functions to be able to detect elements inside the iframe and then change the dom:

$( "body" ).on( "click", "#button", function() {
    $("#idOfYourIframe").contents().find("#textareaID").val("NEW VALUE");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM