1 回答

TA貢獻1744條經(jīng)驗 獲得超4個贊
更新了更多信息
這似乎是一個以多種方式表現(xiàn)出來的錯誤 - 聲稱在這里修復(fù)了一個不相關(guān)的來源 - https://bugs.chromium.org/p/chromium/issues/detail?id=792990
通知功能本身的選項并不多,您只能使用openWindow
創(chuàng)建或使用窗口來執(zhí)行附加選項。
MDN 也承認 Chrome 面臨的問題 - https://developer.mozilla.org/en-US/docs/Web/API/Clients/openWindow
這里有兩種方法
打開或關(guān)注您的應(yīng)用程序并添加
hash
哪些服務(wù)器作為單擊通知的標(biāo)記 - 這使您可以添加目標(biāo)_top
或_blank
歸功于MDN的偽代碼
// Notification click event listener
self.addEventListener('notificationclick', e => {
// Close the notification popout
e.notification.close();
// Get all the Window clients
e.waitUntil(clients.matchAll({ type: 'window' }).then(clientsArr => {
// If a Window tab matching the targeted URL already exists, add a "#mailNotification"
const hadWindowToFocus = clientsArr.some(windowClient => windowClient.url === e.notification.data.url ? (windowClient.navigate(e.notification.data.url+"#mailNotification").then(function(client){client.focus()}), true) : false);
// Add additional code to add a
// Otherwise, open a new tab to the applicable URL and focus it.
if (!hadWindowToFocus) clients.openWindow(e.notification.data.url+"#mailNotification").then(windowClient => windowClient ?
windowClient.navigate(e.notification.data.url+"#mailNotification").then(function(client){client.focus()})
: null);
}));
// Then in your page, you can just use window.onhashChange event
window.onhashchange = weFixChromeLinks
function weFixChromeLinks () {
// ... Create an anchor tag that is formatted to your mailto has a target _top or _blank, hide the link and dispatch a click.
}
較早的方法
由于該clients.openWindow方法不提供以_top窗口為目標(biāo)的能力,因此您可能必須設(shè)置一個支持 a 的中間頁面_top- 即
// Your intermediate page
window.open('mailto...','_top')
結(jié)束語 問題本身很丑- 瀏覽器應(yīng)該知道意圖,例如:應(yīng)用程序、郵件程序等 - 似乎 Chrome for android 將其視為另一個 URL 并且慘遭失敗。
添加回答
舉報