gpt4 book ai didi

javascript - 使用 JavaScript 编辑 iFrame 元素(同域)

转载 作者:行者123 更新时间:2023-11-28 15:18:41 25 4
gpt4 key购买 nike

已更新(带有示例链接)

链接:https://brotherhoodgaming.net/ (点击导航菜单> 设置> 配置文件设置)

我正在使用 iFrame 将我网站的另一个页面加载到我的索引页面上。它应该都来自同一个域。当我的 iFrame 页面加载时,它还会加载主导航菜单的副本。我想删除此 iFrame 导航菜单,只使用一个充满内容的纯框架。

我的 iFrame 是在用户单击按钮时使用 javascript 附加创建的。

$("#menuOverlay").append("<iframe id='iframeContact'' src='contact.php' width='300' height='100%' frameborder='0'></iframe>");

在创建 iframe 之后,我下面的 JS 应该删除框架内的导航菜单,但到目前为止它还没有奏效。 (更新的 JS)

$("#iframeContact").contents().find("#nav").remove();

有什么建议吗?我一直在寻找这个,上面的 JS 被推荐,但我无法找到它来定位框架内的元素。是因为我的frame是通过JS append创建的,其他函数没来得及运行吗?

enter image description here

enter image description here

最佳答案

试试这个。删除类不会删除元素本身。只是元素上的类。假设您所有的选择器都是正确的,这应该可行。

它正在处理链接,但您需要确保在执行代码之前您的 iframe 已完全加载。

var iframe = $("#iframeContact");
iframe.on("load",function ()
{
iframe.contents().find("#nav").remove();
});

关于javascript - 使用 JavaScript 编辑 iFrame 元素(同域),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38833917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com