-1
Kotlin
class MainActivity : AppCompatActivity() {
    private lateinit var myWebView: WebView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        myWebView = findViewById(R.id.webView)

        // webView setting
        myWebView.webViewClient = MyWebViewClient()
        myWebView.loadUrl("www.naver.com")
    }


    inner class MyWebViewClient: WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            super.onPageFinished(view, url)
            myProgressBar.visibility = View.GONE
        }
    }
}

This code is my android code.

I understand that the WebViewClient class prevents new windows from opening. However, I cannot find the reason for how it prevents new windows from opening. What is the principle by which the WebViewClient class prevents new windows from opening?

I tried to find a solution with ChatGPT and Google, but I couldn't find the answer I was looking for. I don't trust ChatGPT because its reliability is low.

  • what kind of new window is it? Do you want it will be open in others browser app? – KiluSs Mar 24 '23 at 09:29
  • Thank you for your interest. I am practicing with Android WebView, and when I use WebViewClient like the above code, the URL is connected to the internal WebView of the app, but if I don't use it, it is connected to the default browser in the Android device. I am curious about the reason for this. – KRdoncc Mar 24 '23 at 09:40
  • Does this answer your question? [Does WebView need a WebViewClient to work?](https://stackoverflow.com/questions/8740307/does-webview-need-a-webviewclient-to-work) – KiluSs Mar 24 '23 at 09:57
  • Thank you :), but that's not the answer I'm looking for. – KRdoncc Mar 27 '23 at 00:28

1 Answers1

0

myWebView.loadUrl("www.naver.com") }

You should specify a protocol like

myWebView.loadUrl("http://www.naver.com")
}

or

myWebView.loadUrl("https://www.naver.com")
}
blackapps
  • 8,011
  • 2
  • 11
  • 25