jquery 在 iframe 外部加载

发布于 2024-11-29 15:50:52 字数 466 浏览 5 评论 0原文

我有一个非常奇怪的问题,我有一个 iframe 能够与其父级进行通信,但只能以某些特定方式进行。例如,我在 iframe 中有此代码,

$(document).ready(function(){
           parent.document.getElementById('target').style.display = 'none';
});

这隐藏了父页面中名为 target 的 div。很不错。但是这段代码确实是我想要做的(将 page.php 加载到名为 target 的 div 中),即使它以完全相同的方式放置,也不起作用:

$(document).ready(function(){
           parent.document.getElementById('target').load("page.php");
});

有人知道为什么吗? 和平

I have a very strange problem, i have an iframe that is able to communicate with it's parent, but only in some certain ways. For an example i have this code in the iframe

$(document).ready(function(){
           parent.document.getElementById('target').style.display = 'none';
});

This hides a div called target in the parent page. Very nice. But this code wich is really what i want to do (loading page.php into the div called target) does not work even though its placed in the exact same way:

$(document).ready(function(){
           parent.document.getElementById('target').load("page.php");
});

Does anyone know why?
Peace

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

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

发布评论

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

评论(2

偏爱自由 2024-12-06 15:50:52
$(document).ready(function(){
    $('#target', parent.document).load("page.php");
});

尝试一下

$(document).ready(function(){
    $('#target', parent.document).load("page.php");
});

Give that a go

婴鹅 2024-12-06 15:50:52
$(function(){
    $(parent.document).find('#target').load("page.php");
});

你应该工作

$(function(){
    $(parent.document).find('#target').load("page.php");
});

you should work

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