开发者

accessing func in iframe. local to online

HI, i got a simple html page, localy with an iframe. the iframe includes a generated page wh开发者_JS百科ich got a javascript function. i know want to call that function. of course, im getting "permission denied". so since im new to js and all that stuff i dont know if it's actually possible to do that. give me some hints for searching or a nice solution.

i do cal lthe func like: parent.myiframe.myfunc();


I guess the page in the iframe resides on another server / domain. Modern browser do not allow "cross site scripting", see: http://de.wikipedia.org/wiki/Cross-Site_Scripting

If possible, move the site in the iframe to the same server. An alternative (workaround) would be to proxy the page on the local server, so that that for the client it seems to be loaded from the same domain.

Edit: This is also called a "Same Origin Policy". You can only call java script functions in a document that is:

  • from the same domain (www.mydomain.com)
  • from the same subdomain (mail.mydomain.com <- no go!)
  • both use the same port (p.Ex. accessing a http://... document from a http*s*:// document won't work).

There might be another workaround if you have access to the iframe's source: Change the iframe domain to the same as the outer frame's, by applying:

document.domain = "domain.com";

in the iframe source (see http://ajaxian.com/archives/how-to-make-xmlhttprequest-calls-to-another-server-in-your-domain for more information).

Also there is a Draft for "Cross-Origin Resource Sharing" (http://www.w3.org/TR/cors/) that is already partially implemented in several browser, see: http://www.webdavsystem.com/ajax/programming/cross_origin_requests

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜