jQuery- iframe循环父母窗口中的所有divs?

发布于 2025-01-29 17:09:25 字数 314 浏览 5 评论 0原文

我的网站正在使用一些IFRAME,当在一个IFRAME之一中单击一个特定的链接时,我需要在父页面中找到所有其他iFrame并刷新它们。

过去,我使用了以下内容,但这是在父母中运行的。

$('div[id^="site-"]').each(function(i, obj) {
    location.reload();
})

显然,当它在iframe中运行时,这将无法正常工作,因为其他iframe在父母中。无论如何,是否可以找到父母中的每个DIV,其中有ID启动站点 -并刷新它们?

谢谢

My site is using some iframes, when a specific link is clicked in one of the iframes I need to find all the other iframes in the parent page and refresh them.

In the past I've used the following, but that has been run in the parent.

$('div[id^="site-"]').each(function(i, obj) {
    location.reload();
})

Obviously this won't work when it's running in the iframe as the other iframes are in the parent. Is there anyway to find each div in the parent with an ID starting site- and refresh them ?

Thanks

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

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

发布评论

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

评论(1

寄居者 2025-02-05 17:09:25

我使用以下内容在iframe中使用以下操作:

frames = window.parent.document.querySelectorAll('[id^="site-"]');

$.each(frames, function(index, item) {
    console.log ( item )
});

console.log中的每个条目是我需要的元素。

I've got this working using the following in the iframe:

frames = window.parent.document.querySelectorAll('[id^="site-"]');

$.each(frames, function(index, item) {
    console.log ( item )
});

Each entry in the console.log is the element I require.

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