我在asp.net中使用以下javascript进行桌面通知。在按钮上单击此事件可以正常使用权限,但从后面的代码实现时会出错。
并在我的网页上添加了此代码...
<script type="text/javascript">
function notifyMe() {
if (!("Notification" in window)) { alert("This browser does not support desktop notification"); }
else if (Notification.permission === "granted") {
var options = {
body: "This is the body of the notification",
icon: "stupidcodes.com.png",
dir: "ltr"
};
var notification = new Notification("Hi there", options);
notification.onclick = function () {
window.open("http://www.stupidcodes.com/");
};
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === 'granted') {
var options = {
body: 'This is the body of the notification',
icon: 'stupidcodes.com.png',
dir: 'ltr'
};
var notification = new Notification('Hi there', options);
notification.onclick = function () {
window.open('http://www.stupidcodes.com/');
};
}
});
}
}
是否有任何方法可以在asp.net
中添加这样的通知您可以查看此代码是否有效here