gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 01:42:46 24 4
gpt4 key购买 nike

如何将属性值从 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com