2017-10-18 21 views

답변

4

.search 속성을 얻을, 또는 수 서비스 작업자의 범위에서 열려있는 모든 클라이언트 페이지의 URL 그래서 ... 여기에 두 가지를 모두 수행하는 방법은 다음과 같습니다

if (url.searchParams.get('key') === 'value') { 
    // Do something if the URL contains key=value as a query parameter. 
} 
: 당신이 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); 
    } 
}); 

는, 당신은 searchParams property을 사용할 수 있습니다
0

당신은 waiting.scriptURL 얻거나 active.scriptURL, URL() 생성자에 결과를 전달합니다, 당신은 서비스 작업자 스크립트의 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); 
    });