Android- using addJavaScriptInterface to return a value from Javascript

后端 未结 3 2041
猫巷女王i
猫巷女王i 2020-12-30 14:50

So i know there are other posts addressing the same issue, and I think I\'ve followed them to the letter but alas to no avail. I\'m trying to learn how to get my app to int

3条回答
  •  梦谈多话
    2020-12-30 15:28

    I do it by utilizing the onLoadResource in my Webview class.

    Html page:

    
    
    function Submit(){
    
            var username = $('#username').val();
            var urlNew = 'processing.php';
            urlNew = urlNew + '?' + 'username=' + username;
            $('#submit').attr('href', urlNew);
    
            return true;
        }
    
    
        

    So then in my onLoadResource I listen for that url:

    public void onLoadResource(WebView view, String url)
            {
                if(url.contains("http://domain.com/processing.php")){
    
    //process the url and suck out the data
    
    }
    

    This might not be what you need, but there were reasons I had to do it this way so figured it may help you. Also note that I didn't do form submit, I did submit, thats because the onLoadResource won't pick up the form submit.

    Edit: This might help.

提交回复
热议问题