Google Chrome 扩展:在 webkit 通知中使用 Javascript?
我一直在遵循 Google Chrome 扩展程序开发人员指南,并且到目前为止创建一个具有浏览器操作的扩展程序,且不带会触发 webkit 通知的弹出窗口HTML 格式。
事实上,这个 HTML 文件包含操作按钮、链接和 javascript,但它们似乎都没有响应。
这是一种设计行为还是有办法在这些 webkit 通知中嵌入 javascript/链接/按钮?
编辑:
以下是关于该主题的一些新见解:
Javascript
这是一个不起作用的 HTML 通知页面:
<html>
<head>
<script>
alert("hey");
</script>
</head>
<body>
content
</body>
</html>
因此,通知全是空白;不显示文本“内容”。
但如果我删除“警报”,则会显示文本“内容”。
我首先认为 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)
I have been following the Google Chrome Extensions Developer's guide and have been able so far to create an extension with a browser action without popup that would trigger a webkit notification in HTML format.
Fact is that this HTML file contains action buttons, links and javascript, but none of them seems to respond.
Is this a by-design behavior or is there a way for embedding javascript/links/buttons in these webkit notifications?
EDIT:
Here are some new insights on the subject:
Javascript
Here is an HTML notification page that doesn't work:
<html>
<head>
<script>
alert("hey");
</script>
</head>
<body>
content
</body>
</html>
As a result, the notification is all blank ; the text "content" isn't displayed.
But if I remove the "alert", the text "content" is displayed.
I first thought that Javascript was blocking the page from rendering correctly, but I tried something else:
<script>document.write("content");</script>
This javascript command is correctly executed and displays the text "content". We can then assume that Javascript is enabled even in the webkit desktop notifications, but the "alert" function is disabled, and breaks the rendering of the notification page.
Links
Some links work, some don't. Here is a quick list of those I've tested so far:
<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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Chromium 桌面通知 API 规范 中对此进行了全部解释其中明确指出:
It's all explained in the Chromium Desktop Notifications API Specification where it's clearly said that:
更新:
createHTMLNotification()
已从草稿中删除规范以及 Chrome,因此这将不再起作用。最接近的是整个通知窗口上的
onclick
处理程序。它不太容易被发现(看起来不像链接),而且我还没有测试是否可以从它导航到链接。UPDATE:
createHTMLNotification()
has been removed from the draft spec and also from Chrome, so this will no longer work.The closest thing is an
onclick
handler on the whole notification window. It's less discoverable (doesn't look like a link), and I haven't tested if it's possible to navigate to a link from it.