Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check notification permissopn allow or not

function handlePermission() {
            return navigator.permissions
                    .query({name:'notifications'})
                    .then(permissionQuery)
                    // .catch(permissionError);
        }
        
        function permissionQuery(result) {
            console.debug({result});
            var newPrompt;
        
            if (result.state == 'granted') {
                // console.log('granted');
        
            } else if (result.state == 'prompt') {
                newPrompt = Notification.requestPermission();
                swal("Please Allow Notification..","", "error");
        
            } else if (result.state == 'denied') {
                swal("Please Allow Notification..","", "error");
            }
        
            result.onchange = () => console.debug({updatedPermission: result});
        
            return newPrompt || result;
        }
        
        
        handlePermission();
 
PREVIOUS NEXT
Tagged: #check #notification #permissopn
ADD COMMENT
Topic
Name
1+9 =