5

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

6
  • And what is actually inside of the iFrame? And what brwoser do you use? Are you calling this site with the file:// protocol? Commented Sep 25, 2013 at 13:57
  • @JayClaiton It can't be called with the file:// protocol - it's an aspx file ;) Commented Sep 25, 2013 at 13:58
  • The access to the iframe may be restricted by the Cross-Origin-Policy
    – 0xcaff
    Commented Sep 25, 2013 at 13:59
  • @caffinatedmonkey: so what i do?
    – rocky
    Commented Sep 25, 2013 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 stackoverflow.com/questions/9393532/cross-domain-iframe-issue for more information.
    – 0xcaff
    Commented Sep 25, 2013 at 14:09

1 Answer 1

12

Because your frame is not again loaded..

Try

$("#YOURFRAME").load(function (){
  var tmp = $('#results iframe').contents().find('html').html();
  alert(tmp);
});
2
  • Have you set an ID to your frame (called in this example YOURFRAME)
    – Paul Rad
    Commented Sep 25, 2013 at 14:08
  • Can you give me a link please ?
    – Paul Rad
    Commented Sep 25, 2013 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.