I'm currently investigating whether it's possible to write a html/aspx page which contains an iframe which can read values entered in text boxes etc.
Some of the knowns are:
- This will only need to work with IE 7/8
- I have no control over the pages contained in the iframe
- The pages in the iframe are from a different domain
I've tried this with a nested page from the same domain and it works fine; I can read the value of a textbox and display it in a messagebox fine. When I try it with a page from a different domain I get an 'Access Denied' error from IE.
For reference the code I'm using to access form elements of the page 开发者_JAVA百科in the iframe is as follows:
var iframe = document.getElementById("myIframe");
var textBox = iframe.contentWindow.document.getElementById("txtTest");
alert(textBox.value);
I understand that this may not be possible, by design, for security reasons but just want to check first that there's no workarounds before abandoning this idea.
No you can access iframes only if they are in the same domain of the main page.
AFAIK for security reasons you cannot manipulate the parent DOM from an IFrame hosted on a different domain.
精彩评论