2011-11-09 5 views
1

Comment puis-je attraper le navigateur fermer ou plus précisément l'événement de déchargement de la page dans le navigateur android? Je ne pouvais pas le faire fonctionner dans le navigateur Android avec les événements comme unload, beforeunload etc.Catch événement de fermeture de navigateur dans le navigateur android

+0

vous parlez Ceci est-il possible en utilisant la programmation Java ou à partir du Web mobile? –

+0

WebViewClient peut vous être utile: http://developer.android.com/reference/android/webkit/WebViewClient.html –

+0

Je parle de la gestion de cet événement en javascript. – Hari

Répondre

2
/* Tell the client to display a dialog to confirm navigation away from 
the current page. This is the result of the onbeforeunload javascript event. 
If the client returns true, WebView will assume that the client will handle 
the confirm dialog and call the appropriate JsResult method. If the client 
returns false, a default value of true will be returned to javascript to accept 
navigation away from the current page. The default behavior is to return false. 
Setting the JsResult to true will navigate away from the current page, false will 
cancel the navigation. 
    */ 
     public boolean onJsBeforeUnload (WebView view, String url, String message, JsResult result){ 

     } 

de http://developer.android.com/reference/android/webkit/WebChromeClient.html

Je pense que vous pouvez aussi injecter du code dans votre page Web affichée par WebView:

<script type="text/javascript"> 
    function OnBeforeUnLoad() { 
     return ""; 
    } 
</script> 

utilisant

@Override 
    public void onPageFinished(WebView view, String url) 
    { 
     webview.loadUrl("string with your script"); 
    } 
Questions connexes