Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: Unable find elements inside iframe

i have page using iframe:

page a.html:

<div id="results">
  <iframe src="../b.aspx"></iframe>
</div>

now i want to get elements in iframe, so i try:

<script type="text/javascript">
        jQuery(document).ready(function($) {
            var tmp = $('#results iframe').contents().find('html').html();
            alert(tmp);
        });
</script>

but result return is: <head></head><body></body>, don't have content in head or body. i need a help

like image 319
rocky Avatar asked Dec 19 '22 23:12

rocky


1 Answers

Because your frame is not again loaded..

Try

$("#YOURFRAME").load(function (){
  var tmp = $('#results iframe').contents().find('html').html();
  alert(tmp);
});
like image 149
Paul Rad Avatar answered Feb 14 '23 07:02

Paul Rad