【问题标题】:Chrome extension, after opening in tab, window.open() not workingChrome 扩展,在选项卡中打开后,window.open() 不起作用
【发布时间】:2017-01-08 15:10:45
【问题描述】:

我在 Chrome 扩展程序中创建了一个弹出窗口,效果很好。

在弹出窗口中,用户将单击一个按钮并打开一个新选项卡并加载本地扩展包附带的 index.html。

index.html hv 它自己的 .js 文件、css 等。

但是,当在 index.html 中单击按钮时,使用 window.open("url"),chrome 无法从该页面打开新窗口/选项卡。

错误信息:

Refused to display 'https://www.behance.net/' in a frame because it set 'X-Frame-Options' to 'DENY'.

我可以在由 chrome 扩展创建的选项卡中执行 window.open() 什么操作?

【问题讨论】:

标签: javascript google-chrome google-chrome-extension window.open


【解决方案1】:

经过一番挖掘,我找到了解决方案。这比我想象的要容易。

出于某种原因 window.open("url") 不工作

神奇的是使用这个函数来触发点击事件:

winUrl(x){
     var a = document.createElement('a');
    a.href = x;
    a.target='_blank';
    a.click();
  };

再次,我是编码新手,所以我不太确定发生了什么修复了所有错误。

有人愿意评论和解释吗?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-25
  • 2020-11-25
  • 1970-01-01
相关资源
最近更新 更多