Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:04:36+00:00 2026-06-12T17:04:36+00:00

I followed the instructions as given in Using The Notifications API . Also I

  • 0

I followed the instructions as given in Using The Notifications API. Also I faced many problems like the below, because I added the document.querySelector() inside the <head> part:

Uncaught TypeError: Cannot call method 'addEventListener' of null

Now I have the below source, where I am able to Check Notification Support, and Check Notification Permissions links.

Guide me how to bring in notifications in a simpler way. Also, I tried this:

$("#html").click(function() {
    if (window.webkitNotifications.checkPermission() == 0) {
        createNotificationInstance({ notificationType: 'html' });
    } else {
        window.webkitNotifications.requestPermission();
    }
});

Now I am stuck with this source. I need to generate HTML & Simple Notifications. Am I missing something? Please guide me.

Source:

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title>Desktop Notifications</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            function checkNotifications() {
                if (window.webkitNotifications)
                    alert("Notifications are supported!");
                else
                    alert("Notifications are not supported for this Browser/OS version yet.");
            }
            function createNotificationInstance(options) {
                if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
                    if (options.notificationType == 'simple') {
                        return window.webkitNotifications.createNotification('icon.png', 'Notification Title', 'Notification content...');
                    } else if (options.notificationType == 'html') {
                        return window.webkitNotifications.createHTMLNotification('http://localhost/');
                    }
                } else {
                    window.webkitNotifications.requestPermission();
                }
            }
        </script>
        <style type="text/css">
            * {font-family: Verdana, sans-serif;}
            body {font-size: 10pt; margin: 0; padding: 0;}
            p {margin: 5px;}
            a {color: #09f; text-decoration: none;}
            a:hover {color: #f00;}
        </style>
    </head>
    <body>
        <p><strong>Desktop Notifications</strong></p>
        <p>Lets see how the notifications work in this browser.</p>
        <p>
            <a href="#" onclick="checkNotifications(); return false;">Check Notification Support</a>.
            Next <a href="#" onclick="alert('Notifications are ' + ((window.webkitNotifications.checkPermission() == 0) ? '' : 'not ') + 'allowed!'); return false;">Check Notification Permissions</a>
            and if permissions are not there,
            <a href="#" onclick="window.webkitNotifications.requestPermission(); return false;">Request Permissions</a>.
            Create a
            <a href="#" id="text">Simple Notification</a>
            or
            <a href="#" id="html">HTML Notification</a>.
        </p>
    </body>
    <script type="text/javascript">
        document.querySelector("#html").addEventListener('click', function() {
            if (window.webkitNotifications.checkPermission() == 0) {
                createNotificationInstance({ notificationType: 'html' });
            } else {
                window.webkitNotifications.requestPermission();
            }
        }, false);
        document.querySelector("#text").addEventListener('click', function() {
            if (window.webkitNotifications.checkPermission() == 0) {
                createNotificationInstance({ notificationType: 'simple' });
            } else {
                window.webkitNotifications.requestPermission();
            }
        }, false);
    </script>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:04:37+00:00Added an answer on June 12, 2026 at 5:04 pm

    After creating the notification, you need to call show() on it, so instead of just:

    createNotificationInstance({ notificationType: 'simple' });
    

    you need to do:

    var n = createNotificationInstance({ notificationType: 'simple' });
    n.show();
    

    The other thing is: when doing jQuery code, wrap it inside

    $(document).ready(function() {
      // ...
      // your jQuery code
      // ...
    });
    

    When doing actions on the DOM with jQuery inside the head, the DOM isn’t build yet. $(document).ready waits until the DOM is build and you can savely access and manipulate it.

    Here is a working example: http://jsfiddle.net/fkMA4/

    BTW: I think HTML notifications are deprecated, see here: http://www.html5rocks.com/en/tutorials/notifications/quick/?redirect_from_locale=de

    Notifications with HTML content have been deprecated. Samples and text
    have been modified accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do ssh connection using cygwin. I have followed instructions given
I followed the instructions given in the link: http://blog.avirtualhome.com/how-to-compile-a-new-ubuntu-11-04-natty-kernel/ for building a custom kernel
I've followed all instructions given on this site with an empty .vim folder, but
I'm trying to extend Python 3 using instructions given here and I'm fairly confident
I've followed the instructions given here for introducing an existing SQLite database to your
I created the instance of linux on EC2. I followed the exact instructions given
I'm using the KnpMenuBundle in my application, and I have followed their instructions to
I followed the instructions given on devise page . Only thing different is that
I've followed instructions from this question on SO to set up RVM, rubies and
I downloaded the codeigniter extension of HybridAuth here: https://github.com/andacata/HybridIgniter I followed instructions on its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.