我一直在关注 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/