loufar
loufar

Reputation: 47

Inject JavaScript in Android after WebView has finished loading from a previous JavaScript Injection

I have a Webview, that onPageFinished injects some JavaScript, this JavaScript populates the form on this page and submits the form successfully.

My question is how do i then check for onPageFinished of the page the WebView goes to after the form has been submitted? As i wish to inject some more JavaScript to pull out some values.

Thanks in advance.

Upvotes: 0

Views: 1185

Answers (1)

ripopenid
ripopenid

Reputation: 185

You need to manage yourself redirection through a flag that you manipulate in all 3 relevant methods:

boolean loadingFinished = true;
boolean redirect = false;

mWebView.setWebViewClient(new WebViewClient() {

   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
       if (!loadingFinished) {
          redirect = true;
       }

   loadingFinished = false;
   view.loadUrl(urlNewString);
   return true;
   }

   @Override
   public void onPageStarted(WebView view, String url, Bitmap facIcon) {
        loadingFinished = false;
        //SHOW LOADING IF IT ISNT ALREADY VISIBLE  
    }

   @Override
   public void onPageFinished(WebView view, String url) {
       if(!redirect){
          loadingFinished = true;
       }

       if(loadingFinished && !redirect){
         //HIDE LOADING IT HAS FINISHED
       } else{
          redirect = false; 
       }

    }
});

Upvotes: 2

Related Questions