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

标签 javascript html

场景

打开新标签页(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/

相关文章:

Javascript 高级 console.log

javascript - 在 Head 加载之前渲染 HTML 页面

javascript - 如何创建特定网页的预览?

javascript - JQuery查找并删除值中点击的id号

javascript - 使用 HTML 和/或 Javascript 自包含登录

javascript - 如何在 Loopback 3 中定义管理员角色?

javascript - cordova 如何从 http 或 https url 打开应用程序?

javascript - 无法根据 Ajax 请求加载新的 HTML 内容

javascript - object 对象和未定义的 GET 变量

javascript - 为什么这种处理数组的方式不是最优的?