简体   繁体   English

从父级在iFrame中执行Javascript

[英]Executing Javascript in iFrame from Parent

Just a heads up I am a semi noob at JavaScript. 请注意,我是JavaScript的半菜鸟。

So for the past two days I have been googleing and for the life of me I cannot figure out how to execute a function in an iframe from the parent page. 因此,在过去的两天里,我一直在谷歌搜索,对于我一生来说,我无法弄清楚如何在父页面的iframe中执行函数。 The page in the iframe is on a different domain and the code to be executed is usually executed via a link, but I want it to be executed without have the users click on the link. iframe中的页面位于不同的域上,通常要通过链接执行要执行的代码,但是我希望无需用户单击链接就可以执行它。

I hope that made some sense. 我希望这是有道理的。 If you guys would like to see what I have so far just let me know, but I don't think it would be of much help since it doesn't work at all. 如果你们想看到我到目前为止所拥有的,请告诉我,但我认为这不会有太大帮助,因为它根本无法工作。

AFAIK, you can not execute JavaScript from a different domain in another fram due to security restrictions in most browsers (definitely Mozilla ). AFAIK,由于大多数浏览器(绝对是Mozilla )的安全性限制,您无法从另一个框架中的其他域执行JavaScript

I have heard rumors of a way around that with Yahoo! 我听说有传言称雅虎可以解决这一问题 Pipes but must cofess that I never investigated that so don't know if that is the case. 管道,但必须承认我从未调查过,所以不知道是否是这种情况。

Just google for "same origin policy workaround" and see if any of the workarounds listed serve your purpose. 只需在Google上搜索“相同的原产地政策解决方法”,然后查看所列的任何解决方法是否都能满足您的目的。

Different domain? 不同的域? You can't . 你不能

https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript describes one way of adjusting the domain of a page with limits. https://developer.mozilla.org/zh_CN/Same_origin_policy_for_JavaScript描述了一种调整带有限制的页面域的方法。

There is one exception to the same origin rule. 同一原产地规则有一个例外。 A script can set the value of document.domain to a suffix of the current domain. 脚本可以将document.domain的值设置为当前域的后缀。 If it does so, the shorter domain is used for subsequent origin checks. 如果这样做,则将较短的域用于后续的来源检查。 For example, assume a script in the document at http://store.company.com/dir/other.html executes the following statement: 例如,假设位于http://store.company.com/dir/other.html的文档中的脚本执行以下语句:

There are other ways of communicating between frames that don't blur domain boundaries, such as http://ajaxian.com/archives/crossframe-a-safe-communication-mechanism-across-documents-and-across-domains . 框架之间还有其他不模糊域边界的通信方式,例如http://ajaxian.com/archives/crossframe-a-safe-communication-mechanism-across-documents-and-across-domains

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM