browserSettings.allowPopupsForUserEvents 编辑

A BrowserSetting object that can be used to enable or disable the ability of web pages to open popups in response to user actions.

The underlying value is a boolean.

By default, browsers allow web pages to open popups in response to a particular set of events: for example, click, mouseup, submit. If allowPopupsForUserEvents is set to false, no user events will be able to open popups. If it is set to true, the default set of events will be allowed to open popups.

For example, suppose a web page has code like this:

window.addEventListener("click", (e) => {
  window.open("https://example.com","myPopup",'height=400,width=400');
});

By default, this will open a popup window. If your extension sets allowPopupsForUserEvents to false, then it will not open a popup, and the user will be informed that the popup was blocked.

Browser compatibility

BCD tables only load in the browser

Examples

Toggle the setting:

function toggleAllowPopup() {

  function toggle(current) {
    console.log(`Current value: ${current.value}`);
    browser.browserSettings.allowPopupsForUserEvents.set({value: !current.value});
  }

  browser.browserSettings.allowPopupsForUserEvents.get({}).then(toggle);
}

browser.browserAction.onClicked.addListener(() => {
  toggleAllowPopup();
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:105 次

字数:2263

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文