检测IFRAME文档是否格式错误 [英] Detect if IFRAME's document is malformed

查看:111
本文介绍了检测IFRAME文档是否格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将页面加载到IFRAME中,并且我想知道下载是否不完整,并且HTML格式错误,并且缺少结束标记,如< / body> < / html>



有没有什么办法可以在JavaScript中检测到这个问题?

解决方案

我不确定您是否可以测试格式不正确的HTML或缺少元素,而不知道具体到底会指望和测试什么。



如果您有权访问iframe页面可以在绑定到父窗口的< / body> 结束之前调用javascript函数变量; (或者使用window.onLoad()事件来调用触发器。)



在你的容器页面中定义这个方法。

  window.iAmLoaded = function(){
alert('iframe loaded OK');
};

然后从iframe调用它;

 < script type =text / javascriptcharset =utf-8> 
window.parent.iAmLoaded();
< / script>
< / body>

如果这不是一个选项,并且iframe有一个相当知名的DOM或一个独特的元素在页面结尾处,可以使用getElementById或者您最喜欢的库的CSS选择器方法来定位元素。

I'm loading a page into an IFRAME, and I would like to know if the download was incomplete .. and the HTML is malformed, and missing the closing tags like </body> and </html>.

Is there any way to detect this in JavaScript?

解决方案

I'm not sure if you can test for malformed HTML or missing elements without knowing exactly what to expect and testing for it specifically.

If you have access to the source of the iframe page you could call a javascript function variable before the end of the </body> bound to the parent window; (or use the window.onLoad() event to call trigger the call.)

Define this method in your container page.

window.iAmLoaded = function() { 
    alert('iframe loaded OK');
};

Then call it from the iframe;

    <script type="text/javascript" charset="utf-8">    
        window.parent.iAmLoaded();    
    </script>
</body>

If this is not an option, and the iframe has a fairly well known DOM, or a distinctive element near the end of the page, you can use getElementById or your favourite library's CSS selector method to locate the element.

这篇关于检测IFRAME文档是否格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆