gpt4 book ai didi

javascript - 将数据从选项卡 1 传递到选项卡 2

转载 作者:行者123 更新时间:2023-11-28 09:17:16 25 4
gpt4 key购买 nike

我是 stackoverflow 的新手,我来到这里是因为我无法找到关于 html 和 javascript 问题的明确答案。

我想显示一个带有 3 个按钮的 HTML 页面,这些按钮将在单击时执行 3 个脚本。我需要 tab#1 与 tab#2 对话来执行代码,但我不知道如何去做 - 这是我的 HTML 代码:

<!DOCTYPE html>
<html>
<body>

<!-- START STAGE 1 -->
<script>
function stage1()
{
// Here I want to open up a new tab so I'd do:
window.open('http://webpage.com', '_blank');
}
</script>

<!-- START STAGE 2 -->
<script>
function stage2()
{
// From here, I want to execute some JavaScript to the new tab I've opened
}
</script>

<!-- START STAGE 3 -->
<script>
function stage3()
{
// Again, I want to execute another script on the new tab I've opened
}
</script>

<button type="button" onClick="stage1()">STAGE1</button>
<hr />
<button type="button" onClick="stage2()">STAGE2</button>
<hr />
<button type="button" onClick="stage3()">STAGE3</button>
</body>
</html>

如果有人可以重写此代码并在 3 中留一个空格,以便我的代码在 tab#1 的 tab#2 上执行,我将不胜感激。

提前谢谢您! - 抱歉,我有点菜鸟哈哈。干杯,德克兰土地

最佳答案

这并不简单,但我认为您可以使用“代理”页面来实现,该页面在 iframe 中显示目标站点 (Twitter),并在您通过时运行您需要的脚本地址中的参数(例如 proxy.htm?action=step2 ),甚至为每个步骤使用单独的专用代理页面 (proxy2.htm)。

但为了使其正常工作,我相信您需要为 anchor 链接的目标使用自定义名称 (a target="proxy_twitter"),以便所有链接都以相同的方式打开选项卡。

一个可能的问题是,第二个选项卡会在每次点击时重新加载代理页面,但也许可以通过将参数更改为主题标签来避免这种情况 (proxy.htm#action=step2) 。

我自己对这种机制没有任何经验,但我见过它在一些网站上使用。

关于javascript - 将数据从选项卡 1 传递到选项卡 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15502838/

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