0

I have this JS / PHP Code:

<iframe src="" id="contacts_iframe" width="100%" height="300px" scrolling="no" frameborder="0"></iframe>
<script>
function() {
    $('#contacts_iframe').load(function() {            
        if($.trim($(this).contents().find("body").html()) == "") {
            alert("empty");
            <?php echo $ContactsDisplay; ?>
        }
    });
});
</script>

I want to be able to echo the $ContactsDisplay variable if the iframe is empty

I added the alert in to test, but the alert does not show and neither does the PHP variable.

What could be going wrong?

charlie
  • 1
  • 5

1 Answers1

-2

Your nearly there try this.

 if($( "#frameDemo" ).contents().length == 0){
   alert('success loaded');
 } else {
   alert('fail not loaded');
 }

success
<iframe src="//api.jquery.com/" width="80%" height="600" id="frameDemo"></iframe>

fail
<iframe src="www.sdfsdfdsf.com" width="80%" height="600" id="frameDemo"></iframe>
Matthew A Thomas
  • 924
  • 7
  • 15