简体   繁体   English

从iframe(chrome)中获取父窗口(窗体)元素

[英]Get parent window (form) element from within an iframe (chrome)

I have a simple (main) page with a iframe within it. 我有一个简单的(主)页面,其中包含iframe。
The (main) page has a form, which i need to access from within iframe (主页面)有一个表格,我需要从iframe中访问

From within the iframe i am trying to refer to form elements in the main page. 我试图从iframe中引用主页中的表单元素。

I have tried all of these - but with no success in Chrome browser : 我已经尝试了所有这些方法-但在Chrome浏览器中没有成功

top.document.getElementById('myform'); top.document.getElementById('myform');
Error message: Cannot call method 'getElementById' of undefined 错误消息:无法调用未定义的方法“ getElementById”

parent.getElementById('myform'); parent.getElementById('myform');
Error message: Object [object global] has no method 'getElementById' 错误消息:对象[全局对象]没有方法'getElementById'

parent.document.myform.mytextbox.value; parent.document.myform.mytextbox.value;
Error message: Cannot read property myform of undefined. 错误消息:无法读取未定义的属性myform。

In IE - i can simply do - works in IE : 在IE中-我可以简单地- 在IE中工作

parent.document.myform.mytextbox.value; parent.document.myform.mytextbox.value;

If it matters: I am trying this on my desktop, the html pages are not hosted in any webserver. 如果很重要:我正在桌面上尝试此操作,则html页面未托管在任何Web服务器中。 So there is no domain as such... 所以没有这样的领域...

Any idea? 任何想法? I am hoping to make it work in Firefox and also find something that works in IE, Chrome, FireFox 我希望它可以在Firefox中运行,并且还能找到在IE,Chrome,FireFox中可以运行的功能

EDIT 编辑
I am also seeing this message (via developer tools of chrome): 我还看到了此消息(通过chrome开发人员工具):

Blocked a frame with origin "null" from accessing a frame with origin "null". 阻止源为“ null”的帧访问源为“ null”的帧。 Protocols, domains, and ports must match. 协议,域和端口必须匹配。

Is this what is root cause of the issue? 这是问题的根本原因吗?

尝试使用iframe src =“ page.php?param = value”和onchange函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM