gpt4 book ai didi

javascript - 如何在子窗口的父窗口中运行脚本?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:39:12 24 4
gpt4 key购买 nike

我的 child.html 有一个按钮,可以使用脚本 $('[value="Submit"]').click();我想从 parent.html

调用它

像这样:

var popUp = window.open('https://child.html');
popUp.$('[value="Submit"]').click();
//这一行应该修复

怎么会这样?

最佳答案

你应该使用 window.postMessage应用程序接口(interface)。这是示例代码。

child.html

function functionToBeExecuted(event)
{
// do click or whatever you want
}

window.addEventListener("message", functionToBeExecuted, false);

parent.html

let child = window.open('child.html');

child.postMessage(); // notice that I did not pass message argument, since you just want to trigger the function, but if you want to pass some data to function using event parameter, just pass data to this function (for example string or object etc.)

关于javascript - 如何在子窗口的父窗口中运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54364168/

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