我正在尝试在我的聊天应用程序中实现HTML5通知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)
}
附言:我正在使用ReactJS,Redux进行我的前端开发。
发布于 2018-06-19 21:44:25
在Chrome62和更新版本中,除非站点是
://安全的,否则你根本不能请求通知api。(见问题779612)如果你的网站上有https,你应该能够使用通知和后台推送通知。
https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
https://stackoverflow.com/questions/50929223
复制相似问题