2016-09-02 1 views
0

developers.google.com에 따르면 Web App Install 배너를 연기 할 수는 있지만 완전히 취소 할 수는 있습니다.지연 웹 설치 배너

window.addEventListener('beforeinstallprompt', function(e) { 
    console.log('beforeinstallprompt Event fired'); 
    e.preventDefault(); 
    return false; 
}); 

한 사용 사례가 함께 참여하는 것을 나타 내기 위해서 (뭔가를 사용자가 작업을 수행 한 직후 예를 들어, 때까지 나중에 페이지의 라이프 사이클에서 프롬프트를 연기 또는 페이지 하단에 충돌하는 것입니다 대지).

웹 앱 배너를 어떻게 연기 할 수 있습니까?

답변

2

도움이 될만한 경우 documentation을 확인해보십시오.

다음은 프롬프트를 연기하는 데 사용하는 전체 코드입니다.

var deferredPrompt; 

window.addEventListener('beforeinstallprompt', function(e) { 
    console.log('beforeinstallprompt Event fired'); 
    e.preventDefault(); 

    // Stash the event so it can be triggered later. 
    deferredPrompt = e; 

    return false; 
}); 

btnSave.addEventListener('click', function() { 
    if(deferredPrompt !== undefined) { 
    // The user has had a postive interaction with our app and Chrome 
    // has tried to prompt previously, so let's show the prompt. 
    deferredPrompt.prompt(); 

    // Follow what the user has done with the prompt. 
    deferredPrompt.userChoice.then(function(choiceResult) { 

     console.log(choiceResult.outcome); 

     if(choiceResult.outcome == 'dismissed') { 
     console.log('User cancelled home screen install'); 
     } 
     else { 
     console.log('User added to home screen'); 
     } 

     // We no longer need the prompt. Clear it up. 
     deferredPrompt = null; 
    }); 
    } 
}); 

자세한 내용은 link을 확인하십시오.

+1

'deferredPrompt == undefined' 일 때 무엇을 해야할지 흥미로운 ... – 4esn0k

+0

사용자가 사용자 정의 버튼을 클릭하면 그 값이'null '이되는'if (deferredPrompt)'여야합니다. –