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

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

问题描述

我正在尝试访问表单及其元素.表单位于 iframe 中,访问表单的 javascript 代码位于主文档中.

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)

谢谢

推荐答案

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

或者您可以在框架中使用一些代码将 parent 中的变量设置为表单,但我不相信该方法.

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天全站免登陆