【问题标题】:If Statement To Check if a Table is contained in an IframeIf 语句检查表是否包含在 iframe 中
【发布时间】:2018-07-11 09:05:13
【问题描述】:

对不起,如果这个问题看起来很简单,但我找不到任何简单的解释,而且我是 JavaScript 新手,所以请提供任何帮助/反馈。

基本上我有一个名为iframe 的HTML iframe,我想要一个JavaScript if 语句来查看其中是否有<table> 对象。我不知道如何在 if 语句中引用它。任何帮助将不胜感激。

【问题讨论】:

标签: javascript html css django


【解决方案1】:

所以你想检查框架中是否有任何表格。

为此, 给 iframe 一个 id ,比如

<iframe id ="myFrame">
    <!-- your code goes here -->
</iframe>

然后在 JavaScript 代码中:

var frame = document.getElementById("myFrame");
var len = frame.getElementsByTagName("TABLE").length;
if ( len == 0 ){
  // the frame contains no tables
}
else{
   // the frame contains one or more tables
}

希望对你有帮助

【讨论】:

  • 谢谢!这正是我想要的。
  • 很高兴听到这个消息。将此标记为正确答案,以便对其他人有所帮助
【解决方案2】:

据我所知,由于Same Origin policy,您通常无法访问 iframe 的内容。

【讨论】:

    猜你喜欢
    • 2017-10-02
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多