开发者

Google Chrome extension: Use Javascript inside webkit notifications?

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)


It's all explained in the Chromium Desktop Notifications API Specification where it's clearly said that:

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜