Trang web này sẽ có chức năng hạn chế trong khi chúng tôi trải qua bảo trì để cải thiện trải nghiệm của bạn. Nếu một bài viết không giải quyết được vấn đề của bạn và bạn muốn đặt câu hỏi, chúng tôi có cộng đồng hỗ trợ của chúng tôi đang chờ để giúp bạn tại @FirefoxSupport trên Twitter và /r/firefox trên Reddit.

Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Tìm hiểu thêm

How to trigger desktop notification through a webpage?

  • 6 trả lời
  • 1 gặp vấn đề này
  • 13 lượt xem
  • Trả lời mới nhất được viết bởi user1251572

more options

I am in need of doing some debugging work which entails me triggering a desktop notification through Firefox, now I am currently unable to do this with a normal webpage that would do this due to my current circumstances. However I still need to test this so I thought that perhaps I could create an HTML page and just include whatever is necessary to launch the desktop notification through Firefox. And then open that page in Firefox.

I am running Firefox 47 on Ubuntu GNOME 16.04 with GNOME 3.20, how can I trigger a desktop notification through a webpage? Is there some code I need to run or something?

I am in need of doing some debugging work which entails me triggering a desktop notification through Firefox, now I am currently unable to do this with a normal webpage that would do this due to my current circumstances. However I still need to test this so I thought that perhaps I could create an HTML page and just include whatever is necessary to launch the desktop notification through Firefox. And then open that page in Firefox. I am running Firefox 47 on Ubuntu GNOME 16.04 with GNOME 3.20, how can I trigger a desktop notification through a webpage? Is there some code I need to run or something?

Giải pháp được chọn

Do you mean a normal notification?

You can create an HTML file with this content:

<!DOCTYPE html><html><head><script type='text/javascript'>
var RunOnDomReady = function() {
function authorizeNotification(){Notification.requestPermission(function(perm){alert(perm);});}
function showNotification() {
 var notification = new Notification("This is a title", {
     dir: "auto",lang: "",body: "This is a notification body",tag: "sometag",
 });
}
document.querySelector("#authorize").onclick = authorizeNotification;
document.querySelector("#show").onclick = showNotification;
}
document.addEventListener("DOMContentLoaded", function(){RunOnDomReady();}, false);
</script></head><body><button id="authorize">Authorize notification</button><button id="show">Show notification</button></body></html>
Đọc câu trả lời này trong ngữ cảnh 👍 0

Tất cả các câu trả lời (6)

more options

This is functionality offered by the website. It's nothing you can turn on if the site doesn't offer it. https://support.mozilla.org/kb/push-notifications-firefox

more options

christ1 said

This is functionality offered by the website. It's nothing you can turn on if the site doesn't offer it. https://support.mozilla.org/kb/push-notifications-firefox

Oh no, I didn't mean that I wanted to turn it on for a website which doesn't support it. I just meant that I want to know how to create an offline website which I can open and does support it so that I can test whether or not I get the desktop notification (as currently no website gives me one and I have been asked to do some debugging work).

more options

Giải pháp được chọn

Do you mean a normal notification?

You can create an HTML file with this content:

<!DOCTYPE html><html><head><script type='text/javascript'>
var RunOnDomReady = function() {
function authorizeNotification(){Notification.requestPermission(function(perm){alert(perm);});}
function showNotification() {
 var notification = new Notification("This is a title", {
     dir: "auto",lang: "",body: "This is a notification body",tag: "sometag",
 });
}
document.querySelector("#authorize").onclick = authorizeNotification;
document.querySelector("#show").onclick = showNotification;
}
document.addEventListener("DOMContentLoaded", function(){RunOnDomReady();}, false);
</script></head><body><button id="authorize">Authorize notification</button><button id="show">Show notification</button></body></html>

Được chỉnh sửa bởi cor-el vào

more options

cor-el said

Do you mean a normal notification?

If by "normal" you mean just the normal desktop notifications (like I can get Gmail to give me when I receive an email), then yes.

more options

Did you try to open a file with the above posted HTML code to see if that is what you mean?

more options

Yes, that is what I wanted. Thank you and sorry for the delay in getting back to you.