0

My Website(use laravel) call window.open method on this code

window.open('My_URL','_blank');

and my Android Webview open new window on dialog. code is

override fun onCreateWindow(view:WebView, isDialog:Boolean,
    isUserGesture:Boolean, resultMsg:Message):Boolean {

    // set dialog webview
    val dialog = Dialog(context)
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
    dialog.setContentView(R.layout.activity_webview)

    val newWebView = dialog.findViewById<WebView>(R.id.WebView)

    newWebView.settings.javaScriptEnabled = true
    newWebView.loadUrl(view?.url)

    // open dialog full screen
    val window = dialog.window
    val wlp : WindowManager.LayoutParams = window.attributes
    wlp.gravity = Gravity.CENTER
    wlp.flags = WindowManager.LayoutParams.FLAG_BLUR_BEHIND
    window.attributes = wlp
    dialog.window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.MATCH_PARENT)
    dialog.show()
    (resultMsg.obj as WebView.WebViewTransport).setWebView(newWebView)
    resultMsg.sendToTarget()

    newWebView.setWebViewClient(object: WebViewClient() {

    })

    newWebView.setWebChromeClient(object:WebChromeClient() {
        override fun onCloseWindow(window:WebView) {
            dialog.dismiss()
            window.destroy()
            newWebView.destroy()
            //webview.removeView(newWebView)
        }
    })

    return true
}

it was work successful just one time.

what should I do?

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
Cronian
  • 23
  • 1
  • 7

1 Answers1

1

Not sure if it will help you or not, but as far as I know the android application should provide handling of opening and closing window requests from javascript. I mean it does work out of the box, but very often not how it is expected/needed.

It is possible to show separate web window as a dialog, but as I know dialogs can't stack and appear on top of each other. Such approach fits case when you need to open (and then close) only one separate window. Please read more about dialogs here.

What I suggest is to show separate WebView on every window.open() request. Please take a look at this answer, where similar solution was solved. In your case (where any amount of opened windows possible) you can use a LinkedList of WebViews, pushing new one on window.open() and popping top ones on window.close.

Demigod
  • 5,073
  • 3
  • 31
  • 49