Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

桌面端发送消息 #287

Closed
oeyoews opened this issue Oct 19, 2024 · 0 comments
Closed

桌面端发送消息 #287

oeyoews opened this issue Oct 19, 2024 · 0 comments

Comments

@oeyoews
Copy link
Owner

oeyoews commented Oct 19, 2024

if(!("Notification" in window)) {
	//alert("This browser does not support desktop notification");
}
if(Notification.permission !== 'denied') { //判断是否授权,没授权先授权在通知
	Notification.requestPermission(function(permission) {
		// 如果用户同意,就可以向他们发送通知
		if(permission === "granted") {

			var notice_ = new Notification('通知', {
				body: '你有一条信息'
			});
			notice_.onclick = function() { //单击消息提示框,进入浏览器页面
				window.focus();
			}
		}
	});
}
if(Notification.permission === 'denied') { //已授权直接通知
	Notification.requestPermission(function(permission) {
		// 如果用户同意,就可以向他们发送通知
		if(permission === "granted") {

			var notice_ = new Notification('通知', {
				body: '你有一条信息'
			});
			notice_.onclick = function() { //单击消息提示框,进入浏览器页面
				window.focus();
			}
		}
	});
}
@oeyoews oeyoews closed this as completed Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant