How to get new URL parameters in a Webview?

Issue

I would like to ask how to implement this, i have an application where in if i click a certain button it will access a webview in-app browser, the problem is that from the webview there is a button that, when clicked will redirect into a new page. the question is how am i able to get the URL of that new page? for example. the original URL is www.abc.com/home and when I clicked the button on the web page it will go to another page www.abc.com/page2. how to get the www.abc.com/page2. I am able to get www.abc.com/home easily using onPageFinished. but cant gets the next page. note that I clicked the button on the webpage itself. i used already the shouldOverrideUrlLoading but it doesn’t work. any ideas? a good example will do. thank you!

Solution

Check this Out :

WebView webview  new WebView(context);
webview.setWebViewClient(new WebViewClient()
        {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);

                Log.d("WebView", "your current url when webpage loading.." + url);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                Log.d("WebView", "your current url when webpage loading.. finish" + url);
                super.onPageFinished(view, url);
            }

            @Override
            public void onLoadResource(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onLoadResource(view, url);
            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                System.out.println("when you click on any interlink on webview that time you got url :-" + url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });

Answered By – Muntasir Aonik

Leave a Comment