等待iframe加载并使用某些值



我有一个跨域iframe,如果未加载内容,我需要显示一个警报消息。

var noContent = true;
 $("#iframe1").load(function () {
          noContent = false;               
        });
if(noContent)
//do my logic

现在我的if零件在加载之前执行iframe,我无法验证是否有内容。

任何建议??

您需要在回调中移动IF:

var noContent = true;
 $("#iframe1").load(function () {
   //check if the contents are OK here  
   if(noContent) ...
 });

最新更新