如何检查iFrame中是否包含值

How to Check if an iFrame Has a Value In It

本文关键字:iFrame 是否 包含值 检查 何检查      更新时间:2023-09-26

我在父窗口中有以下iframe:

<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>

现在在www.myurl.com中,假设我有一个基于某些标准显示3个字段的报告。

因此,基于此,我如何从父窗体检查上面描述的iframe是否为空数据,即没有列出报告数据,或者使用jquery/javascript确实有数据?

基本上只需要知道iframe中的报表是有0行还是有1行或更多行。

谢谢。

如果是内部URL,可以使用jQuery的加载来获取页面的内容。

如果是外部URL,则不能。

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