views:

227

answers:

3

How do i send a JavaScript function to an iframe with external content loaded,

eg

onclick="getElementByID('myiframe').src='fun();'"

is there a way with ajax, i think XMLHttpRequest can help me.

A: 

You can't, it's a security feature

Mike Robinson
A: 

everything must be on the same domain. or you will need to setup a proxy

ctrlShiftBryan
A: 

As stated earlier you cannot do this because of the builtin security model of the browsers.

However, if the two sites are hosted on the same subdomain, for example appA.company.com and appB.company.com, you can get around it using domain relaxation. All you have to do is to set the document.domain in both pages to company.com. See http://www.tomhoppe.com/index.php/2008/03/cross-sub-domain-javascript-ajax-iframe-etc/ for more information

dparnas