开发者

Javascript: error in access IFrame on local files

开发者 https://www.devze.com 2023-02-26 19:22 出处:网络
I use some iframes in my page and I\'d like to access iframe elements from parent page and the opposite.

I use some iframes in my page and I'd like to access iframe elements from parent page and the opposite.

From the parent page I add Iframes with:

<iframe id="iframe1" src="./iframe1.html" width="100%" height="100%"></iframe>

and I try di access iframe element by javascript with:

window.frames['iframe1']
...

From iframes I use something like

//to get elements
var obj = parent.document.getElementById('iframe1');
//to call methods
parent.document.mymethod();

In both situation it give me the following error:

Unsafe JavaScript attempt to access frame with URL file:///C:/Users/marco/test/iframe1.html from frame with URL file:///C:/Users/marco/test/index.html. Domains, protocols and ports must match.

I know that file have to be in the same domain. The problem is that I don't call files from web server, but browser has to read files directly from resource path. This because I will put theese files embedded in an Android app and I will read them with a webview from local resources. I tried to set manually window.domain = 'mydomain' but nothing changed and also to use absolute path for iframes.

I use Sencha Touch, if it can be usefull.

Any开发者_开发技巧 ideas? Thanks for your time,

Marco

0

精彩评论

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