JavaScript可以从父页面访问iframe元素吗? [英] Can javascript access iframe elements from the parent page?

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

问题描述

我在页面上有iframe,iframe和父页面在不同的域中,可以在父页上的JavaScript代码中访问这个iframe中的元素?

I have iframe on a page, the iframe and the parent page are in different domain, can a javascript code on the parent page access elements inside this iframe?

推荐答案

如果页面来自不同的域,浏览器安全沙箱应该阻止这种类型的访问。当两个页面来自同一个域的不同 sub 域时,它可能会起作用,但浏览器(甚至可能是同一浏览器的版本)之间可能会不同。

It should not be able to if the pages are from different domains, the browsers security sandbox should prevent this type of access. It might work when the two pages are from different sub domains of the same domain, but that can and will differ between browsers (and possibly even versions of the same browser).

访问子iframe可能工作,但其他方式肯定不会工作。

Accessing the child iframe might work, but the other way around will most certainly not work.

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

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