I have been writing a Javascript file that calls a for loop and on each iteration of the loop programmatically creates a new link that gets pushed to the user via browser push notification. These unique links are also appended to the notifications as onclick events. I run the code and try to click on the notifications, however I found that rather than each notification having it's own unique onclick link, all consecutive notifications have taken on the onclick of the most recent notification.
I have included a barebones code here that demonstrates the issue I'm facing: https://jsbin.com/loyeviguqu/1/edit?html,js,output
*edit: sorry I quickly realized I had linked to the wrong jsbin, the correct link is now updated
From the code I have written, you will see that I create 3 links google.com/0, google.com/1, google.com/2 with a for loop. Furthermore in the for loop for each iteration I append the link as a onclick event to the notification. However you will see clicking on any of the 3 notifications will always result in the google.com/2, rather than any of the other two. The text in the notifications however retain their uniqueness.
My current suspicion is the each time I append an onclick to the notification it overwrites the old one, however I'm at a loss at how to fix this.
Any explanation or insight into the issue would be greatly appreciated! Thanks!