gpt4 book ai didi

javascript - 可以使用 target 和 window.name 吗?

转载 作者:太空狗 更新时间:2023-10-29 16:00:13 26 4
gpt4 key购买 nike

场景

打开新标签页(http://example.com/slave)。进入控制台:

window.name = "example-slave"

打开新标签页(http://example.com/master)。添加 HTML:

<a href="http://example.com" target="example-slave">Click me!</a>

预期效果

添加的链接应该在第一个选项卡(example-slave)中打开 example.com。

当前效果

添加的链接正在打开新窗口,然后每次额外的点击都会在此窗口中打开 example.com。

问题

这正常吗?有没有可能达到预期的效果?

最佳答案

参见 the specification :

If the given browsing context name is not _blank and there exists a browsing context whose name is the same as the given browsing context name, and the current browsing context is familiar with that browsing context, and the user agent determines that the two browsing contexts are related enough that it is ok if they reach each other, then that browsing context must be the chosen one.

您的场景的问题是用户使用浏览器控件打开了两个浏览上下文。他们彼此不熟悉,根本没有关系,所以不能互相修饰。

要使它们相关联,您需要使用 targetwindow.open() 打开一个。

关于javascript - 可以使用 target 和 window.name 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31201326/

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