首页 > 解决方案 > 如何从新窗口运行 javascript 到现有窗口

问题描述

const winHtml = `<button id="cool">Run code on other window</button>`;

const winUrl = URL.createObjectURL(
    new Blob([winHtml], { type: "text/html" })
);

const win = window.open(
    winUrl,
    "win",
    `width=800,height=400,screenX=200,screenY=200`
);

所以我希望能够从一个用 JS 打开的新窗口运行代码。这不是一个新的浏览器选项卡,它是一个插入了 html 的新浏览器窗口。是否可以将代码从它运行到现有的浏览器窗口?

标签: javascript

解决方案


推荐阅读