将 JavaScript 添加到 iframe 中?

发布于 2024-12-22 08:19:25 字数 232 浏览 4 评论 0原文

我想知道是否可以将 javascript 添加到页面上的 iframe 或框架集?

请注意:内容来自同一域 www.domain.com 但子域不同 www.blah.domain.com 与 www.blah2.domain.com ,我不确定这是否重要。

I want to know if it is possible to add a javascript <script type="text/javascript">blahblah</script> to an iframe OR frameset that is on the page?

Just a note: the content comes from the same domain www.domain.com but the subdomain is different www.blah.domain.com vs www.blah2.domain.com, I'm not sure if that matters.

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

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

发布评论

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

评论(1

夜深人未静 2024-12-29 08:19:25

这确实很重要,但幸运的是有一个相当简单的修复方法。您只需将两侧的 document.domain 属性设置为同一个域(例如,document.domain = 'domain.com'

document.domain 只能设置为同一个超级域,因此您无法对 www.example.comblah.example2.com 执行此操作。

设置了 document.domain 属性后,您应该能够以与位于同一子域时相同的方式连接 iframe。

以下是如何将脚本标记插入 iFrame 的方法:将脚本插入 iFrame 的标头,而不清除 iFrame 的主体

It does matter but luckily there's a fairly simple fix. You just need to set the document.domain property on both sides to the same domain (e.g., document.domain = 'domain.com')

document.domain can only be set to the same super domain so you couldn't do this with www.example.com and blah.example2.com.

Once you have the document.domain property set you should be able to interface the iframe the same way you would if they were on the same subdomain.

Here's how to insert the script tag into the iFrame: Insert a Script into a iFrame's Header, without clearing out the body of the iFrame

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