4

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

rocky
  • 329
  • 4
  • 9
  • 21
  • And what is actually inside of the iFrame? And what brwoser do you use? Are you calling this site with the file:// protocol? – Jay Claiton Sep 25 '13 at 13:57
  • @JayClaiton It can't be called with the `file://` protocol - it's an aspx file ;) – Reinstate Monica Cellio Sep 25 '13 at 13:58
  • The access to the iframe may be restricted by the Cross-Origin-Policy – 0xcaff Sep 25 '13 at 13:59
  • @caffinatedmonkey: so what i do? – rocky Sep 25 '13 at 14:05
  • If the frame's origin is on a different origin(domain) that your's you might not be able to access the frame. There is nothing you can do about it. See http://stackoverflow.com/questions/9393532/cross-domain-iframe-issue for more information. – 0xcaff Sep 25 '13 at 14:09
  • @caffinatedmonkey Since he's using a relative URL for the iframe src, it must be in the same domain. – Barmar Jan 19 '15 at 09:16

1 Answers1

11

Because your frame is not again loaded..

Try

$("#YOURFRAME").load(function (){
  var tmp = $('#results iframe').contents().find('html').html();
  alert(tmp);
});
Paul Rad
  • 4,820
  • 1
  • 22
  • 23