Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    addEventListener without "click" function.

    Hello! I need help with a javascript code
    I want this notification when the "clasamea" div element is shown on the page. Ex.

    I have 1 forumotion notification, its ID is #notif_unread.. what should i use instead of "click" to see this desktop notification without changing the page ?

    Partial code:
    var testing= document.getElementsByClassName('clasamea')[0];
    testing.addEventListener("click", function () {
    if (Notification && Notification.permission === "granted") {
    var n = new Notification("Hey...");
    }

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,135
    Thanks
    12
    Thanked 332 Times in 328 Posts
    I want this notification when the "clasamea" div element is shown on the page.
    since this div is probably created by a server-side language, there will be no event. just test with JS whether this div exists (or has content).

    if this div is created through JS, just hook your notification into that creation process.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,190
    Thanks
    10
    Thanked 569 Times in 550 Posts
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •