0

So i want my web page to promt for validation on desktop notifications when it loads. So i added onload in body...

<body onload="setAllowNotification() return false;">

This works jsut fine on mozilla firefox but in Google chrome it doesn't show the question. But if i call that function like this, it works.

<a onclick="setAllowNotification(); return false;" href="#">Click to set allow notifications</a> 

If it helps my setAllowNotification function:

function setAllowNotification()
    {
    window.webkitNotifications.requestPermission(permissionGranted);
    }

So any ideas?

gabrjan
  • 3,080
  • 9
  • 40
  • 69

1 Answers1

0

Try adding a semicolon to your onload event inline code:

Check this answer actually...

Webkit notifications requestPermission function doesn't work

You can only use it as part of a response to a user action - i.e. you cannot do it "onload"

Community
  • 1
  • 1
theyetiman
  • 8,514
  • 2
  • 32
  • 41
  • so what's the best way to do this kind of stuf? And why does is work in firefox? – gabrjan Sep 14 '12 at 09:46
  • I'm certainly no expert on it, but it's only a draft specification so each browser will have its own implementation which may be slightly different to other browsers. I'd hazard a guess that Firefox allows you to do it `onload` but Chrome doesn't. Perhaps you could try triggering the `click` event in the `onload` event? It **might** fool Chrome, but I doubt it. – theyetiman Sep 14 '12 at 10:00