Use Javascript to block page access when Web Browser Push Notification not granted

Usage

You want to allow only web push notification subscribers to access a particular page.

If push notification is not granted, the visitor will be alerted and redirected to another page.

Implementation

Create push-test.js with following code

if (Notification.permission !== "granted") {
    alert("Please allow web notification to get your discount coupon code!");
    window.location.replace("https://help.moddiy.com/en/article/can-i-get-a-discount-coupon-1tuojwu/");
}

Add the following code to the page you want to protect

<script src="https://www.moddiy.com/javascript/push-test.js"></script>

Leave a Reply

Your email address will not be published. Required fields are marked *