Android WebView에서 URL 이동한 후 close이벤트 발생 시

창을닫으려고 하니까 onCreateWindow, onCloseWindow가 동작을 안하더라고?

 

왜그런지 싶어서 webChromeClient 에서 발생하는 로그 출력을 해봤음.

 

Scripts may close only the windows that were opened by them.

Scripts may close only the windows that were opened by it. 

 

이런 오류가 뜨는거 확인하고 찾아봐도 답이 안나오길래

그냥 이 에러메세지 발생했을 때 엑티비티 닫아버렸음.

private class webChromeClient extends WebChromeClient {
   
    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
        String error = consoleMessage.message();
        Log.d("mytag2", error);
        if (error.equals("Scripts may close only the windows that were opened by them.")) {
            finish();
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);

            startActivity(intent);
        }

        return super.onConsoleMessage(consoleMessage);
    }
}

이게 맞나싶다..

 

 

 

 

+ Recent posts