2017-10-18 15 views

答えて

4

.searchプロパティを取得することができますサービスワーカーのスコープで開いているすべてのクライアントページのURL。だから... ...ここの両方を行う方法は次のとおりです。これらのケースのいずれにおいても

// Get a URL object for the service worker script's location. 
const swScriptUrl = new URL(self.location); 

// Get URL objects for each client's location. 
self.clients.matchAll({includeUncontrolled: true}).then(clients => { 
    for (const client of clients) { 
    const clientUrl = new URL(client.url); 
    } 
}); 

、あなたがURLオブジェクトを持っていたら、あなたはクエリパラメータに興味があるなら、あなたはそのsearchParams propertyを使用することができます。

if (url.searchParams.get('key') === 'value') { 
    // Do something if the URL contains key=value as a query parameter. 
} 
0

あなたは私はあなたがサービスワーカースクリプトのURLを取得する方法について求めているかどうかについての明確ではないよ、または、waiting.scriptURLまたはactive.scriptURLを取得URL()コンストラクタにつながる渡し、オブジェクト

navigator.serviceWorker.register("sw.js?abc=123") 
    .then(function(reg) { 
    const scriptURL = reg.waiting && reg.waiting.scriptURL || reg.active.scriptURL; 
    const url = new URL(scriptURL); 
    const queryString = url.search; 
    console.log(queryString); 
    }).catch(function(err) { 
    console.log("err", err); 
    }); 
関連する問題