第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法從服務(wù)人員打開 mailto: 和 tel: 鏈接?

有沒有辦法從服務(wù)人員打開 mailto: 和 tel: 鏈接?

炎炎設(shè)計 2022-10-21 14:44:02
我正在使用服務(wù)工作者處理的推送通知。使用通知的主要動機是提供“呼叫”或“郵寄至”等操作,但我認為該行為與單擊“郵寄:”鏈接相同。它在 Windows 上使用 chrome 工作(例如在點擊時啟動郵件應(yīng)用程序),但在 android 上使用 chrome 失敗,導(dǎo)致一個黑色標(biāo)簽,上面寫著 url“mailto:...”。// Service Workerself.addEventListener('notificationclick', function(event) {  const { contactRequest } = JSON.parse(event.notification.data);  switch(event.action) {    case 'call':      return clients.openWindow('tel:' + contactRequest.phone);    case 'mail':      return clients.openWindow('mailto:' + contactRequest.email);  }});
查看完整描述

1 回答

?
慕無忌1623718

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

這里有兩種方法

  1. 打開或關(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 并且慘遭失敗。


查看完整回答
反對 回復(fù) 2022-10-21
  • 1 回答
  • 0 關(guān)注
  • 89 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號