gpt4 book ai didi

javascript - 如何控制合适的iframe?

转载 作者:太空宇宙 更新时间:2023-11-04 03:39:53 25 4
gpt4 key购买 nike

我的代码/网站嵌入到 iframe 中。它位于同一域中,因此我可以毫无问题地访问父文档。

问题是我的代码所在的 iframe 是动态生成的 - 每次站点重新加载时它都会获得一个新 ID 并且没有类。

所以,我有这段代码:

$("iframe", window.parent.document).each(function () {
var iFrame = this;

if ($("#controlAddIn",iFrame)) {
iFrame.css({"height": "29px", "padding-bottom": "12px"});
}
});

Firefox 控制台给了我这个:

TypeError: iFrame.css is not a function

我想要实现的是重新调整 iframe 的大小,其中我的代码是固定值 + 更改填充。

我的解决方案有什么问题,firefox 不想执行它?

谢谢。

最佳答案

这是因为你的iFrame设置为this.css 是一个 jQuery 函数,this 不是 jQuery 对象。
因此,您要么必须通过将 $(this) 分配给它来使您的 iFrame 成为 jQuery 对象,或者使用纯 JavaScript 为其分配样式。

$(this).css({"height": "29px", "padding-bottom": "12px"});

this.style.height = '29px';
this.style.paddingBottom = '12px';

关于javascript - 如何控制合适的iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25057705/

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