我可以使用 jquery 选择器引用子 iframe 的全局变量吗?

发布于 2024-10-08 01:41:32 字数 410 浏览 0 评论 0原文

我需要在我的页面中动态创建一个 iframe,当我关闭它时,它将从我的页面中删除。 (事实上​​,它是 jquery 插件 "fancybox"

它总是最后一个 iframe。我想要在iframe中引用页面的全局变量。所以我认为 $("iframe:last").globalvariable 会起作用。我把它放在 $(function(){……}) 。然而事实并非如此。

我已经知道框架的 id 和 name ,我可以通过“id”或“name”来实现吗?

我可以使用选择器引用子iframe的全局变量吗?或者在这种情况下,我该如何实现?

谢谢

I need create a iframe dynamically in my page,when I closed it ,it will be removed from my page.
(In fact it jquery plugin "fancybox")

It always the last iframe.I want quote the page's global variable in the iframe.So I think the $("iframe:last").globalvariable would work.I put it in $(function(){……}) .However it does not.

I already know frame's id and name ,Can I achieve that through "id" or "name"?

Can I use selector quote child iframe's global variable?Or in this case,how can I achieve that ?

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷你仙 2024-10-15 01:41:32

从父母的角度:

var iFrameValue = $('#iframe').get(0).contentWindow.mySpecialFunction();

或者

var iFrameValue = $('#iframe').get(0).contentWindow.myLocalVariable;

从 iframe 的角度

<script type="text/javascript">

var myLocalVariable = "hello";

function myLocalFunction () {
    return "hello";
}

</script>

From the parents perspective:

var iFrameValue = $('#iframe').get(0).contentWindow.mySpecialFunction();

OR

var iFrameValue = $('#iframe').get(0).contentWindow.myLocalVariable;

From the iframe perspective

<script type="text/javascript">

var myLocalVariable = "hello";

function myLocalFunction () {
    return "hello";
}

</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文