[英]HTML5 Web Notification Permission Issue
我正在尝试在我的聊天应用程序中实现HTML5 Notification API。 当我在本地主机上工作时,一切正常(浏览器提示我是否需要允许来自此站点的通知)。
但是,当我尝试从所有连接在同一网络中的其他计算机访问在本地计算机上运行的应用程序时。 浏览器未提示任何内容。
总结我的问题:
http:// localhost:3000 / home-可行 !
http://10.1.0.126:3000/home-这种方式行不通。 (即使从我的计算机或其他计算机尝试我的计算机)
这是我用于通知api实现的代码
function createNotification(response){
if(!('Notification' in window)){
console.log("This browser does not Notification")
}else{
if(Notification.permission === 'granted'){
createNotification(response) // function to createNotification from response
}else if(Notification.permission !== 'denied'){
Notification.requestPermission((permission) => {
if(permission === 'granted'){
createNotification(response)
}
})
}
function createNotification(response){
// Construct the Notification
let title = response.sender_name
let notificationOptions = {
body: response.message,
icon: default_profile_pic
}
// Close the Notification after 3 seconds
let notification = new Notification(title, notificationOptions)
setTimeout(notification.close.bind(notification),3000)
}
PS:我正在使用ReactJS,Redux进行前端开发。
在Chrome 62及更高版本中,除非该网站受到https://的保护,否则您根本无法请求通知api。 (请参阅问题779612)如果您的站点上确实有https,则应该可以使用通知和后台推送通知。
https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.