Reputation: 95
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:
I'm getting
Permission denied to access property 'js_function'
When doing
document.getElementById("iframe").contentWindow.js_function(n)
Upvotes: 3
Views: 12665
Reputation: 38046
Use easyXDM's RPC feature, it combines XDM with RPC. An example of this can be seen here: http://consumer.easyxdm.net/current/example/methods.html
Upvotes: 0
Reputation: 159905
Even though the script is hosted on main.com
it is executed in the context of example.com
and therefore is considered to be part of example.com
... and therefore has no access to variables or functions in the main.com
window. You can hack around this with various cross domain communication hacks (or you can ignore IE < 8 and use window.postMessage
by itself).
SEE ALSO: http://stevehanov.ca/blog/index.php?id=109
Upvotes: 5
Reputation: 28124
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.
Upvotes: 1