0

i develop on my local desktop machine with brackets. I currently try something with browser notifications. The strange thing is, that this code:

<!doctype html>
<html>

<head>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>

<body>
    <button id="btn_not">Click me to get notified</button>
    <script type="text/javascript">
        $(document).ready(function () {
            if (Notification.permission !== "granted") {
                Notification.requestPermission();
            }
            $("#btn_not").click(function () {
                createNotification();
            })
        })

        function createNotification() {
            var notification = new Notification("Hi there!");
        }
    </script>
</body>

</html>

doesn't work on my local machine but it does work perfectly if I upload it to my webserver, but I don't understand why?

binaryBigInt
  • 1,526
  • 2
  • 18
  • 44
  • Web pages loaded from the local filesystem have stricter restrictions than files loaded from a server. I'm not 100% that's the reason here, but I think that's the most likely reason. You could check [this question](http://stackoverflow.com/questions/19902538/loading-local-files-with-javascript-without-a-web-server) – Schlaus Jul 17 '16 at 20:51
  • And on your local machine you're running something like wamp, easyphp etc. or do you just open the file with the `file://` protocol? – adeneo Jul 17 '16 at 20:59
  • 1
    Note for Chrome, sites loaded from the filesystem (eg file:///), `Notification.permission` is `default` and thus acts like `denied`, and doing requestPermission() always leads to a `denied` permission – Patrick Evans Jul 17 '16 at 21:00
  • Yes, i basically just use file:///. Thanks @PatrickEvans Maybe i should use XAMPP instead. – binaryBigInt Jul 17 '16 at 21:02

0 Answers0