如何从父javascript页面访问子iframe元素? [英] How to access child iframe elements from a parent javascript page?

查看:90
本文介绍了如何从父javascript页面访问子iframe元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,我有iframe代码。当我点击我框架窗口启用的particluar链接时。它是一个表单。当我提交表单时,我得到一些隐藏的字段值。我可以在我的父页面中访问这些值吗?。

In my page i have iframe code. When i click particluar link that i frame window enabled.it is a form.when i submit the form i get some hidden field values.how can i access those values in my parent page?.

推荐答案

由于你的iframe src =一个完整的url,而不是一个相对路径(即:/app/appsignup.jsp),我将假设这个iframe存在于另一个IP或域名比原始页面。如果这个假设是正确的,那么由于大多数浏览器中的跨站点脚本安全规则,您将无法修改Iframe的DOM。

Since your iframe src= a complete url, and not a relative path (i.e: /app/appsignup.jsp) I am going to assume this Iframe exists at another IP or domain than the original page. If this assumption is correct, then you are not going to be able to modify the Iframe's DOM due to cross site scripting security rules in most browsers.

如果父网站和子iframe存在于同一顶级域中,则可以使用document.getElementById(iframe_id)

If the parent site, and child iframe exist on the same top level domain, then you can use document.getElementById("iframe_id")

编辑以回答第二个问题:

Edit to answer second question:

您可以向iframe添加onLoad事件,只要iframe只有1个表单,并且页面仅在提交时更改,这是您要重定向的位置。

You can add an onLoad event to the iframe, and so long as the iframe only has 1 form, and the page only changes when submitted, and this is where you want to be redirected.

这是一个例子,但知道这会在第一次重定向而不起作用!
你想要做的是在那里放一个函数,然后在该函数的.js中检查第二个onLoad ...

Here is an example, but know this will redirect the first time and not work! What you will want to do is put a function in there, and then in the .js for that function check for the second onLoad...

<iframe name="signUp" id="signup" src="10.80.32.9:8080/app/appsignup.jsp"; width="650" height="500" onLoad="window.location('/index.html');">

这篇关于如何从父javascript页面访问子iframe元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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