tonyf
tonyf

Reputation: 35557

How to Check if an iFrame Has a Value In It

I have the following iframe within a parent window:

<iframe
   name="sg_iframe" 
   id="sg_iframe" 
   src="www.myurl.com"
   align="left"
   height="150px" 
   width="750"
   frameborder="0" 
   marginheight="0" 
   marginwidth="0"
   overflow="auto">
</iframe>

Now within www.myurl.com, let’s say I have a report that display 3 fields based on some criteria.

So based on this, how can I check from the parent form whether the iframe described above is empty of data, i.e. no report data listed or actually does have data using jquery/javascript?

Basically just need to know if the report within the iframe has 0 rows or 1 or more rows.

Thanks.

Upvotes: 2

Views: 1813

Answers (2)

Shahin
Shahin

Reputation: 12841

$('iframe').each(function() {
    if($(this).contents().find('#content').text() == '') {
        $(this).addClass('warning');
    }
});

Upvotes: 0

Sean Powell
Sean Powell

Reputation: 1437

If it's an internal URL, you can use jQuery's load to get the page's content.

If it's an external URL, you can't.

Upvotes: 1

Related Questions