javascript - 谷歌浏览器扩展 : Use Javascript inside webkit notifications?

标签 javascript html webkit notifications google-chrome-extension

我一直在关注 Google Chrome Extensions Developer's guide并且到目前为止已经能够创建一个带有 browser action 的扩展没有会触发 HTML 格式的 webkit 通知的弹出窗口。

事实上,这个 HTML 文件包含操作按钮、链接和 javascript,但它们似乎都没有响应。

这是设计使然的行为还是有办法在这些 webkit 通知中嵌入 javascript/链接/按钮?

编辑:

以下是关于该主题的一些新见解:

Javascript

这是一个不起作用的 HTML 通知页面:

<html>
<head>
<script>
  alert("hey");
</script>
</head>
<body>
  content
</body>
</html>

结果,通知全是空白;未显示文本“content”

但如果我删除“警报”,则会显示文本“内容”

我最初以为是 Javascript 阻止了页面正确呈现,但我尝试了其他方法:

<script>document.write("content");</script>

此 javascript 命令已正确执行并显示文本 “content”。然后我们可以假设即使在 webkit 桌面通知中也启用了 Javascript,但是 “警报” 功能被禁用,并且中断了通知页面的呈现。

链接

有些链接有效,有些无效。以下是我迄今为止测试过的那些的快速列表:

<a href="http://www.google.com/">Link</a>                   # => Doesn't work
<a href="http://www.google.com/" target="_top">Link</a>     # => Doesn't work
<a href="http://www.google.com/" target="_parent">Link</a>  # => Doesn't work
<a href="http://www.google.com/" target="_blank">Link</a>   # => Works (new tab)

最佳答案

这一切都在 Chromium Desktop Notifications API Specification 中进行了解释明确指出:

If a user agent implements createHTMLNotification, it should show HTML notifications as independent browsing contexts which are equivalent in functionality to any other HTML web page, except with the following properties:

  • The notification cannot be navigated. The Location attribute of the window object in the notification context should be readonly. All links should open in new, non-notification browsing contexts.
  • If close() is invoked on the window object in the notification context in response to a user gesture, the user agent should proceed as if the user closed the notification, including all required event processing.

关于javascript - 谷歌浏览器扩展 : Use Javascript inside webkit notifications?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2889276/

相关文章:

javascript - 根据 W3C,我应该如何将 Canvas 放入剪贴板?

javascript - AngularJS 中的数组未获取字符串值

javascript - 在我的网页中加载外部页面时 x-frame-options sameorigin

python - CentOS:QtWebKit 丢失,Anki 无法启动

html - 在包含 DIV 的外部定位内部 DIV - 内部 DIV 大小未知 - 需要 CSS 解决方案

javascript - Node.js 错误 : EADDRINUSE, 地址已被使用

javascript - 为什么我的 Google Maps API 回调在前面的内联脚本之前执行?

javascript - 如何使单击列表图像触发单击该列表元素内的链接?

javascript - 如何添加链接切换图片?

javascript - 使用 GTK+ Webkit Webview(和 Qt WebKit 桥)从 JavaScript/HTML 调用 C++