How to access fields in page within iframe?
I have a .aspx page that contains an iframe. I am drawing the embedded page from my ssl server. When I try and modify fields with the embedded page with javascript (I am putting data into hidden fields so that I can use it server side to id the client) I get an access denied message. If i run the whole thing locally I get no problems so really the question is what do I have to change on my ssl server in order to allow those fields to be altered?
The javascript is really straight forward:
window.frames["frame1"].document.forms['password_form']["username"].value = document.getElementById("username").value;
and as i said works apart from when I change the iframe src to ssl...
It's a precompiled app, i'm开发者_高级运维 wondering if that makes a difference. The page itself is not read only.
Thanks, Ron.
The Same Origin Policy prohibits scripting across documents from different origins. The protocol (HTTP/HTTPS) is part of the origin. Therefore the browser must prohibit access to window.frames["frame1"].document
in your example if only iframe is on HTTPS.
The easy solution is to use HTTPS for both the main page and the iframe.
A workaround is possible, but depending on your needs it might be too much hassle: http://softwareas.com/cross-domain-communication-with-iframes (a long, but informative read).
精彩评论