访问iframe中的表单 [英] accessing a form that is in an iframe

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

问题描述

我试图访问表单及其元素。表单位于iframe中,访问表单的JavaScript代码位于主文档中。



我不确定还有什么我应该加入问题的,所以请让我知道是否需要添加别的东西。



(表单和主页在同一个域中)

谢谢

解决方案

  var ifr = document.getElementById(yourIframeId); 
var ifrDoc = ifr.contentDocument || ifr.contentWindow.document;
var theForm = ifrDoc.getElementById(yourFormId);

或者您可以在框架中设置一些代码,在父项中设置一个变量添加到表单中,但我不相信该方法。


I'm trying to get access to a form and its elements. The form is within an iframe and the javascript code that is accessing the form is within the main document.

I'm not sure what else I should put into the question, so please let me know if I need to add something else.

(form and main page are in the same domain)

Thanks

解决方案

var ifr = document.getElementById( yourIframeId );
var ifrDoc = ifr.contentDocument || ifr.contentWindow.document;
var theForm = ifrDoc.getElementById( yourFormId );

Or you could have some code in the frame that sets a variable in parent to the form, but I wouldn't trust that method.

这篇关于访问iframe中的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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