【问题标题】:How to remove contact us form loaded in iframe from html page?如何从 html 页面中删除 iframe 中加载的联系我们表单?
【发布时间】:2017-07-28 14:50:29
【问题描述】:

在搜索了很多并尝试了 5-6 次演示后,但都没有达到我想要的效果。 我有将其他域(网站)的服务显示为 iframe 的服务页面 在该 iframe 下方我有我的联系我们表格,但我的问题是 iframe 页面还包含联系我们页面。我想删除它。

是否可以删除从 iframe 源加载的表单?

编辑:我的代码

<script type="text/javascript">

function remove_elemment() {
    var form = document.forms;


        form.style.display = "none";

    }
};

function doRemove() {
    document.frame.document.getElementById('my_iframe').remove_elemment();
}();

</script>
<div class="floating-widget">
    <iframe id="my_iframe" src="http://192.168.0.104/wordpress/?p=1" frameborder="0" width="100%" height="800">             
    </iframe>

</div>

html中加载的评论表单如下

<div id="respond" class="comment-respond">
   <h3 id="reply-title" class="comment-reply-title">Leave a Reply <small><a rel="nofollow" id="cancel-comment-reply-link" href="/wordpress/?p=1#respond" style="display:none;">Cancel reply</a></small></h3>
   <form action="http://192.168.0.104/wordpress/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
      <p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p>
      <p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>
      <p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" aria-required="true" required="required"></p>
      <p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="email" value="" size="30" maxlength="100" aria-describedby="email-notes" aria-required="true" required="required"></p>
      <p class="comment-form-url"><label for="url">Website</label> <input id="url" name="url" type="url" value="" size="30" maxlength="200"></p>
      <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"> <input type="hidden" name="comment_post_ID" value="1" id="comment_post_ID">
         <input type="hidden" name="comment_parent" id="comment_parent" value="0">
      </p>
   </form>
</div>

【问题讨论】:

标签: javascript php jquery html iframe


【解决方案1】:

这对我有用

$('#MainPopupIframe').on('load', function(){
    $(this).contents().find("#formOrButtonToRemove").Remove();
});

【讨论】:

    【解决方案2】:

    如果iframe 源(服务页面)不是来自同一个域并且没有使用与您的页面相同的协议,那么由于同源策略,它将无法工作。但是如果您的页面在同一个域中并且使用相同的协议,那么您可以使用它来删除联系表。 $("#iframeId").contents().find("#contactformdiv").remove();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      相关资源
      最近更新 更多