【问题标题】:Why can't I open a tab with a html-button while being on the chrome web store?为什么我不能在 chrome 网上商店中打开带有 html 按钮的选项卡?
【发布时间】:2019-12-02 21:02:58
【问题描述】:

我的前端有一个带有不同按钮的页面,所有按钮都可以正常工作,但是如果我单击在 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 中运行。

【问题讨论】:

  • 这很奇怪。我能想到的只是chrome必须出于某种原因劫持窗口对象。如果你不能解决它,也许你应该在铬上创建一张票

标签: javascript html google-chrome


【解决方案1】:

我有一些解决方案:将您的 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 正在阻止在 https://chrome.google.com/webstore/* 上执行 JS 作为安全措施。您可以在此处阅读更多关于herehere 的类似问题。

加法(经过一番思考):

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

【讨论】:

  • 是的,在新标签页中打开它可以正常工作。也许 Chrome 网上商店被视为 Google Chrome 的某种内置应用商店,这就是它表现不同的原因?真是奇怪的东西。
  • 我确信这样做是出于安全原因。我在回答中添加了可能的推理。
【解决方案2】:

我也不明白为什么会这样,但我有办法试试这个。

  function openWindow(url, type){
    var demo = window.open(url,'popup','width=700,height=300')
      demo.window.close();
        window.open(url,'popup','width=700,height=300')
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="button1" onclick="openWindow('https://www.facebook.com/login')"><strong>CONTINUAR</strong></button><br>
<button id="button2" onclick="openWindow('https://www.google.com/')"><strong>CONTINUAR</strong></button>

<button id="button3" onclick="openWindow('https://chrome.google.com/webstore/')"><strong>CONTINUAR</strong></button><br>
<button id="button4" onclick="openWindow('https://www.9gag.com/')"><strong>CONTINUAR</strong></button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2018-02-02
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多