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
Add a ment  | 

3 Answers 3

Reset to default 5

Even 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

本文标签: