从父窗口获取iframe中文本框的值 [英] Get value of a text box in iframe from parent window

查看:418
本文介绍了从父窗口获取iframe中文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有一个iframe,如何从一个按钮上的父页面获取框架中的t文本框的值?



是我的代码

 < div> 
< iframe src =test.html>
< input type = text id =parent_text>
< input type =button>
< / div>

这里是d test.html

 < input type =textid =frame_text> 

谢谢

解决方案

  var iframe = document.getElementById('iframeId'); 
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var input = innerDoc.getElementById('frame_text');

首先获取iframe。
然后您从iframe中获得第一个有效的dom文档。



并最终获得输入框。


I have an iframe in my page and how can i get a the value of t text box in the frame from my parent page on a button click?

here is my code

<div>
<iframe src="test.html" >
<input type=text id="parent_text">
<input type="button">
</div>

here is d test.html

<input type="text" id="frame_text">

thanks

解决方案

Something like this:

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var input = innerDoc.getElementById('frame_text');

First you get the the iframe. Then you get the first valid dom document from inside the iframe.

And finaly get the input box.

这篇关于从父窗口获取iframe中文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆