webview, how can I find out which link was clicked in it?

Nis

I have a webview, how can I find out which link was clicked in this webview?

Android/Java

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        tools:ignore="MissingConstraints">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <include
                android:id="@+id/back"
                layout="@layout/top_menu_back" />

        </androidx.appcompat.widget.Toolbar>

    </com.google.android.material.appbar.AppBarLayout>
    <WebView
        android:id="@+id/newsdetail"
        android:layout_marginTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

hello, I have a webview, how can I find out which link was clicked in this webview?

Nisa Efendioglu

Just use this code snippet. :)

private class MyWebViewClient extends WebViewClient {
    
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                String link = url + "?header=0";
                Log.d("getUrl", link);
                view.loadUrl(link);
                return false;
            }
    
        }

Example :

public class NewsDetail extends AppCompatActivity {

    WebView newsdetail;
    RelativeLayout navigation_icon;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_detail);

        navigation_icon = findViewById(R.id.navigation_icon);

        newsdetail = findViewById(R.id.newsdetail);
        newsdetail.loadUrl(getIntent().getStringExtra("newsdetail"));
        newsdetail.setWebViewClient(new MyWebViewClient());
        WebSettings webSettings = newsdetail.getSettings();
        webSettings.setJavaScriptEnabled(true);
        

    }

    private class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            String link = url + "?header=0";
            Log.d("getUrl", link);
            view.loadUrl(link);
            return false;
        }

    }

}

Note: If the header parameter is allowed by the backend, it does not show the header in the application. To be able to use it I guess it must also be allowed by the backend. Like the header=0 parameter, as in the example.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get my app to get the URL of a link clicked in WebView, perform operations on it, and then load it?

How can I find out which index is out of range?

How can I find out which module a name is imported from?

How can I find out which button was clicked?

How can I keep track of which link the user clicked on using sessions?

How can I find out which functions can be run on an expression?

C# - How to find out which dynamic button was clicked?

How can I find out which ports are available in Kubernetes?

How can I find out which Git commits cause conflicts?

How can I find out which users are in a group within Linux?

How can I find out if a link is "Clean" or "Dirty"?

How to find out which cell was right clicked (despite a differing selection)

How to find out which versions of a package can I install on APT

How can I find out with which software a web page was written?

How can I find out which method of a derived class is not implemented?

How can I find out which user deleted a directory?

How can I find out which table a foreign key references?

How I can find which grid square element I clicked in HTML5 canvas

How can i know which link i clicked in an HTML

How can i get clicked link href?

How can I find out which users are logged in on my computer?

How can i know which link I clicked?

How can I find out what collapsable accordation is clicked?

How can I find out which fonts are available in Turtle?

How can I find out in which directories Firefox looks for plugins?

How can I find out which cards are supported by the nouveau driver?

How to find out which element the user clicked on the touch device

How can I accurately find out, which pom dependency?

How can I find out which sectors are used by files on NTFS?