gpt4 book ai didi

javascript - 无法控制动态添加到页面的iframe

转载 作者:行者123 更新时间:2023-11-29 21:09:03 25 4
gpt4 key购买 nike

我一直在尝试将不可见的 iframe 添加到页面以进行跟踪。我无法从父页面控制该 iframe:这是我完成的代码:

try
{
var frame = document.createElement("iframe");
frame.setAttribute("src", "http://example.com/frame.php");
frame.style.width = "0px";
frame.style.height = "0px";
frame.style.border = "0px";
frame.setAttribute("visibility", "hidden");
frame.setAttribute('id',"awesomeIframe");
frame.style.display = "none";
if(document.body != null)
{
document.body.appendChild(frame);
}
else
{
document.head.appendChild(frame);
}
}catch(e){}

如何修改iframe中包含的js?

最佳答案

您应该获取iframe的内容窗口以便对其进行控制。

记得

它通常在域和协议(protocol)相同时有效。这是下面的代码:

try
{
var frame = document.createElement("iframe");
frame.setAttribute("src", "http://example.com/frame.php");
frame.style.width = "0px";
frame.style.height = "0px";
frame.style.border = "0px";
frame.setAttribute("visibility", "hidden");
frame.setAttribute('id',"awesomeIframe");
frame.style.display = "none";
if(document.body != null)
{
document.body.appendChild(frame);
}
else
{
document.head.appendChild(frame);
}
iframex = document.getElementById("awesomeIframe").contentWindow;
}catch(e){}

** iframex = document.getElementById("awesomeIframe").contentWindow;**使用 iframex 控制 iframe。

关于javascript - 无法控制动态添加到页面的iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42585177/

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