Manipulate the url a webview gets before it starts loading

前端 未结 1 1150
情歌与酒
情歌与酒 2021-01-16 01:38

I would like to add the current location as a request variable to URL\'s loaded in the webview so I can use this information on the page without reloads or extra requests.

1条回答
  •  悲&欢浪女
    2021-01-16 02:05

    Yes, change the Url before you call for loadUrl. You can create one function which modifies the Url and call it for loadUrl and in shouldOverrideUrlLoading

    public Url addLocationToUrl(Url url) {  
        Url newUrl = url;
        //do something with url
        return newUrl;
    }   
    
    loadUrl(addLocationToUrl(someUrl));
    
    //and in your WebViewClient
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        mWebView.loadUrl(addLocationToUrl(someUrl));
        return true;
    }
    

    0 讨论(0)
提交回复
热议问题