admin管理员组文章数量:1296314
I am trying to do the following:
Main document calls a function in iFrame whose URL is from a different location but the Javascript function I'm trying to call loaded from the same domain as the main document.
Is there any way to do this?
To clarify:
- Main document:
- iFrame document:
- JS function i'm calling in iFrame is at .js
I'm getting
Permission denied to access property 'js_function'
When doing
document.getElementById("iframe").contentWindow.js_function(n)
I am trying to do the following:
Main document calls a function in iFrame whose URL is from a different location but the Javascript function I'm trying to call loaded from the same domain as the main document.
Is there any way to do this?
To clarify:
- Main document: http://www.main.
- iFrame document: http://www.example.
- JS function i'm calling in iFrame is at http://www.main./js/script.js
I'm getting
Permission denied to access property 'js_function'
When doing
document.getElementById("iframe").contentWindow.js_function(n)
Share
Improve this question
asked Apr 26, 2011 at 22:16
drtdrt
951 gold badge1 silver badge4 bronze badges
3 Answers
Reset to default 5Even though the script is hosted on main.
it is executed in the context of example.
and therefore is considered to be part of example.
... and therefore has no access to variables or functions in the main.
window. You can hack around this with various cross domain munication hacks (or you can ignore IE < 8 and use window.postMessage
by itself).
SEE ALSO: http://stevehanov.ca/blog/index.php?id=109
I see what you're doing. There was a "hack" that made use of two iframes (if I remember correctly). Both that hack and the one you mention here are awfully obscure, and I wouldn't be surprised if they have been locked down knowingly.
The best fix I can think of is to load the code for js_function()
in the main window (outside of the iframe).
Can you be more specific on what the JS code does? I may be able to help better.
Use easyXDM's RPC feature, it bines XDM with RPC. An example of this can be seen here: http://consumer.easyxdm/current/example/methods.html
本文标签:
版权声明:本文标题:html - Call Javascript Function in Child iFrame with Cross Domain site but Same location JS file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741617214a2388592.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论