【问题标题】:How To Change Title For Alert Dialog Box For Chrome Extension如何更改 Chrome 扩展的警报对话框的标题
【发布时间】:2016-03-17 21:40:38
【问题描述】:

我是第一次编写 Google Chrome 扩展程序,我正在尝试使用 alert() 创建一个对话框,但是当它运行时我遇到了问题。标题不是扩展程序的名称,而是扩展程序 ID(“chrome-extension://..... 说”)。

我希望标题显示扩展名,而不是 ID。这是我的代码:

ma​​nifest.json

{
  //Extension Details
  "manifest_version": 2,
  "name": "Test Extension",
  "description": "Test Extension",
  "version": "1.0",
  "icons" : 
  {
    "16": "PI-Logo.png",
    "32": "PI-Logo.png",
    "64": "PI-Logo.png"
  },
  //Main HTML Action
  "browser_action":
  {
    "default_icon": "PI-Logo.png",
    "default_popup": "popup.html"
  },
  //Permissions
  "permissions":
  [
    "activeTab",
    "https://ajax.googleapis.com/",
    "<all_urls>"
  ],
  "chrome_url_overrides": 
  {
    "newtab" : "newtab.html"
  },
  //Scripts
  "content_scripts":
  [
    {
      "matches": ["http://www.google.com/*", "https://www.google.com/*"],
      "js": ["myScript.js"]
    }
  ],
  "background":
  {
    "scripts": ["background.js"]
  }
}

myScript.js

chrome.runtime.sendMessage("Hello World!");

background.js

chrome.runtime.onMessage.addListener(function(response, sender, sendResponse) {
    alert(response);
});

我对 javascript 或 HTML 了解不多——我是这方面的业余爱好者。关于如何解决此问题的任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 为了记录——请不要在以后使用sn-ps,除非它是一个可以实际运行的简短演示代码。只需使用代码块 - 将代码缩进 4 个空格。
  • 哦,好吧,抱歉,这是我第一次发帖。谢谢你的信息,我以后会这样做的!

标签: javascript jquery html google-chrome google-chrome-extension


【解决方案1】:

不,你不能。出于安全原因(钓鱼之类的),无法更改 JavaScript 警告框标题。

There is plenty of library for modal pop-up 在 JavaScript 中,但在你的情况下,这可能很困难,因为你必须在所有页面中注入它......

另一种几乎可以满足您需求的方法是使用桌面通知 API。它会在屏幕右下角打开一个小弹出窗口,您可以自定义标题。 More information here.

【讨论】:

  • 是否可以将标题更改为chrome扩展名?它是在本教程中完成的 - 我只是不知道如何。 youtu.be/wjiku6X-hd8?t=4m3s
  • @PenguixDarke 我不知道这很奇怪我从来没有成功过。
猜你喜欢
  • 1970-01-01
  • 2013-05-30
  • 1970-01-01
  • 2012-05-27
  • 2020-02-23
  • 2012-09-15
  • 2013-02-22
  • 1970-01-01
  • 2011-03-08
相关资源
最近更新 更多