Wednesday, September 10, 2008

AJAX Exception: Permission denied

While experimenting with AJAX via iFrame, I received following exception:

Error: Permission denied to get property Window.document

It was caught while accessing iFrame's body from the main page by the following way:
document.getElementById(frameId).contentWindow.document.body;

The problem was that I loaded some foreign site into my iFrame and then I triend to access it's body object.

Firefox prevents Javascript from accessing objects (like window's document) of sites different from the original document site. The solution is to place both the main page and content of the iFrame to the same server site.

No comments: