javascript - 如何从 Javascript 中的父级获取 iframe 内的属性值?

标签 javascript iframe

如何将属性值从 iframe 传递给父级?

即iframe (frame1) 有 <a id="a1" href="http://www.infinitybusiness.net"> .如何获得 href 的值(value)在我的父页面中?

最佳答案

var fra = document.getElementById('frameId');
// following will work on same domain (or subdomain with document.domain set) only
var fraContent = fra.contentDocument || fra.contentWindow.document;
myLinkHref = fraContent.getElementById('myLinkId').href;

如果这是跨域的,那么您将需要有权将脚本添加到子框架。如果没有,则没有服务器端代理就无法完成。

关于javascript - 如何从 Javascript 中的父级获取 iframe 内的属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3381920/

相关文章:

javascript - 使用 PDFJS 以全屏模式查看 PDF 文件

javascript mouseout 在交互式 iframe 上触发

javascript - 加载 iframe 作为内容时无法关闭 bootstrap3 模式

javascript - 使用 iframe 下载文件

javascript - 如何在 javascript 中使用另一个函数中的变量

javascript - ES6 Koa.js 运行生成器函数完成并异步返回

javascript - 使用 iFrame 关闭外部点击页面上的菜单

javascript - 在不重新加载 iframe 的情况下检测 iframe 高度变化

javascript - JavaScript 中 Date() 的问题 - 它增加了一个月?

不使用 class 或 id 的 Javascript 切换