首页 > 解决方案 > 为什么我不能在 chrome 网上商店中打开带有 html 按钮的选项卡?

问题描述

我的前端有一个带有不同按钮的页面,所有按钮本身都可以正常工作,但是如果我单击在 chrome 网上商店中打开扩展程序的按钮,然后单击另一个按钮,则页面无法打开.

这是我正在谈论的一个例子。如果您在未关闭正在打开的选项卡的情况下单击按钮,则在 chrome 网上商店打开后单击的按钮将不起作用。有谁知道这是为什么以及如何解决这个问题?

https://html-ichr7r.stackblitz.io

这是它的代码。

<button id="button1" onclick="window.open('https://www.facebook.com/','popup','width=700,height=300');"><strong>CONTINUAR</strong></button><br>
<button id="button2" onclick="window.open('https://www.google.com/','popup','width=700,height=300');"><strong>CONTINUAR</strong></button>

<button id="button3" onclick="window.open('https://chrome.google.com/webstore/detail/dark-mode/dmghijelimhndkbmpgbldicpogfkceaj?hl=de','popup','width=700,height=300');"><strong>CONTINUAR</strong></button><br>
<button id="button4" onclick="window.open('https://www.9gag.com/','popup','width=700,height=300');"><strong>CONTINUAR</strong></button>

任何帮助表示赞赏!

编辑:我刚刚发现它可以在 Firefox 中运行,但仍然不知道为什么它在 Chrome 中不起作用。

标签: javascripthtmlgoogle-chrome

解决方案


我有一些解决方案:将您的 Google 网上商店链接更改popup为类似的其他内容popupWindow,因此您将拥有:

<button id="button1" onclick="window.open('https://www.facebook.com/','popup','width=700,height=300');"><strong>CONTINUAR</strong></button><br>
<button id="button2" onclick="window.open('https://www.google.com/','popup','width=700,height=300');"><strong>CONTINUAR</strong></button>

<button id="button3" onclick="window.open('https://chrome.google.com/webstore/detail/dark-mode/dmghijelimhndkbmpgbldicpogfkceaj?hl=de','popupWindow','width=700,height=300');"><strong>CONTINUAR</strong></button><br>
<button id="button4" onclick="window.open('https://www.9gag.com/','popup','width=700,height=300');"><strong>CONTINUAR</strong></button>

这段代码实际上会有两个不同的弹出窗口。

关于解释,我对这个有点不知所措。我认为 Chrome 正在阻止执行 JShttps://chrome.google.com/webstore/*作为一种安全措施。您可以在此处此处阅读有关类似问题的更多信息。

加法(经过一番思考后):

这可能是 Chrome 开发人员的明智之举。通过不允许任何 JS 更改 上的任何页面https://chrome.google.com/webstore/,他们确信也没有扩展可以更改此页面。想象一下,如果您安装了一个在广告中做得很好的扩展,那么它会得到一个积极的分数,同时它也会改变扩展网络商店的页面。它可能会诱使用户安装其他(hacky/adware-ish)扩展程序或软件,从而感染用户的浏览器或计算机。


推荐阅读