webview not closing onclosewindow
I managed to create a glorious webview app, and running into some challenges:
popup window opens in newwebview, for example a comm100 chat window, sadly I can't get the window to close when chat is finished. not sure what to add to the onPageFinished() and or onCloseWindow()
Any help is much appreciated.
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
final WebView newWebview = new WebView(MainActivity.this);
newWebview.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
WebSettings webSettings1 = newWebview.getSettings();
webSettings1.setJavaScriptEnabled(true);
webSettings1.setDomStorageEnabled(true);
webSettings1.setSupportMultipleWindows(true);
webSettings1.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings1.setAllowFileAccess(true);
webSettings1.setAllowContentAccess(true);
webSettings1.setAllowUniversalAccessFromFileURLs(true);
webSettings1.setAllowFileAccessFromFileURLs(true);
view.addView(newWebview);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebview);
resultMsg.sendToTarget();
newWebview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url){
super.onPageFinished(view, url);
}
});
//return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg);
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
Logcat shows the following error
I/chromium: [INFO:CONSOLE(8)] "Uncaught (in promise) #<Object>", source: https://chatserver.comm100.com/js/bundle.4273ade4b401f37d4797b68863b403e6.js (8)
check out video example Video Link
add a comment |
I managed to create a glorious webview app, and running into some challenges:
popup window opens in newwebview, for example a comm100 chat window, sadly I can't get the window to close when chat is finished. not sure what to add to the onPageFinished() and or onCloseWindow()
Any help is much appreciated.
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
final WebView newWebview = new WebView(MainActivity.this);
newWebview.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
WebSettings webSettings1 = newWebview.getSettings();
webSettings1.setJavaScriptEnabled(true);
webSettings1.setDomStorageEnabled(true);
webSettings1.setSupportMultipleWindows(true);
webSettings1.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings1.setAllowFileAccess(true);
webSettings1.setAllowContentAccess(true);
webSettings1.setAllowUniversalAccessFromFileURLs(true);
webSettings1.setAllowFileAccessFromFileURLs(true);
view.addView(newWebview);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebview);
resultMsg.sendToTarget();
newWebview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url){
super.onPageFinished(view, url);
}
});
//return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg);
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
Logcat shows the following error
I/chromium: [INFO:CONSOLE(8)] "Uncaught (in promise) #<Object>", source: https://chatserver.comm100.com/js/bundle.4273ade4b401f37d4797b68863b403e6.js (8)
check out video example Video Link
add a comment |
I managed to create a glorious webview app, and running into some challenges:
popup window opens in newwebview, for example a comm100 chat window, sadly I can't get the window to close when chat is finished. not sure what to add to the onPageFinished() and or onCloseWindow()
Any help is much appreciated.
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
final WebView newWebview = new WebView(MainActivity.this);
newWebview.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
WebSettings webSettings1 = newWebview.getSettings();
webSettings1.setJavaScriptEnabled(true);
webSettings1.setDomStorageEnabled(true);
webSettings1.setSupportMultipleWindows(true);
webSettings1.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings1.setAllowFileAccess(true);
webSettings1.setAllowContentAccess(true);
webSettings1.setAllowUniversalAccessFromFileURLs(true);
webSettings1.setAllowFileAccessFromFileURLs(true);
view.addView(newWebview);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebview);
resultMsg.sendToTarget();
newWebview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url){
super.onPageFinished(view, url);
}
});
//return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg);
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
Logcat shows the following error
I/chromium: [INFO:CONSOLE(8)] "Uncaught (in promise) #<Object>", source: https://chatserver.comm100.com/js/bundle.4273ade4b401f37d4797b68863b403e6.js (8)
check out video example Video Link
I managed to create a glorious webview app, and running into some challenges:
popup window opens in newwebview, for example a comm100 chat window, sadly I can't get the window to close when chat is finished. not sure what to add to the onPageFinished() and or onCloseWindow()
Any help is much appreciated.
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
final WebView newWebview = new WebView(MainActivity.this);
newWebview.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
WebSettings webSettings1 = newWebview.getSettings();
webSettings1.setJavaScriptEnabled(true);
webSettings1.setDomStorageEnabled(true);
webSettings1.setSupportMultipleWindows(true);
webSettings1.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings1.setAllowFileAccess(true);
webSettings1.setAllowContentAccess(true);
webSettings1.setAllowUniversalAccessFromFileURLs(true);
webSettings1.setAllowFileAccessFromFileURLs(true);
view.addView(newWebview);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebview);
resultMsg.sendToTarget();
newWebview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url){
super.onPageFinished(view, url);
}
});
//return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg);
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
Logcat shows the following error
I/chromium: [INFO:CONSOLE(8)] "Uncaught (in promise) #<Object>", source: https://chatserver.comm100.com/js/bundle.4273ade4b401f37d4797b68863b403e6.js (8)
check out video example Video Link
edited Nov 20 '18 at 15:56
J. Doe
asked Nov 20 '18 at 12:28
J. DoeJ. Doe
165
165
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
fixed by adding WebChromeClient to the onCreateWindow override
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
// popup webview!
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
final WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
newWebView.getSettings().setSupportMultipleWindows(true);
newWebView.getSettings().setDomStorageEnabled(true);
newWebView.getSettings().setAllowFileAccess(true);
newWebView.getSettings().setAllowContentAccess(true);
newWebView.getSettings().setAllowFileAccessFromFileURLs(true);
newWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
newWebView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); //making sure the popup opens full screen
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
newWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
if (newWebView !=null){
webView.removeView(newWebView);
}
}
});
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393002%2fwebview-not-closing-onclosewindow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
fixed by adding WebChromeClient to the onCreateWindow override
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
// popup webview!
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
final WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
newWebView.getSettings().setSupportMultipleWindows(true);
newWebView.getSettings().setDomStorageEnabled(true);
newWebView.getSettings().setAllowFileAccess(true);
newWebView.getSettings().setAllowContentAccess(true);
newWebView.getSettings().setAllowFileAccessFromFileURLs(true);
newWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
newWebView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); //making sure the popup opens full screen
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
newWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
if (newWebView !=null){
webView.removeView(newWebView);
}
}
});
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
add a comment |
fixed by adding WebChromeClient to the onCreateWindow override
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
// popup webview!
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
final WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
newWebView.getSettings().setSupportMultipleWindows(true);
newWebView.getSettings().setDomStorageEnabled(true);
newWebView.getSettings().setAllowFileAccess(true);
newWebView.getSettings().setAllowContentAccess(true);
newWebView.getSettings().setAllowFileAccessFromFileURLs(true);
newWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
newWebView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); //making sure the popup opens full screen
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
newWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
if (newWebView !=null){
webView.removeView(newWebView);
}
}
});
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
add a comment |
fixed by adding WebChromeClient to the onCreateWindow override
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
// popup webview!
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
final WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
newWebView.getSettings().setSupportMultipleWindows(true);
newWebView.getSettings().setDomStorageEnabled(true);
newWebView.getSettings().setAllowFileAccess(true);
newWebView.getSettings().setAllowContentAccess(true);
newWebView.getSettings().setAllowFileAccessFromFileURLs(true);
newWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
newWebView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); //making sure the popup opens full screen
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
newWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
if (newWebView !=null){
webView.removeView(newWebView);
}
}
});
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
fixed by adding WebChromeClient to the onCreateWindow override
public class MainActivity extends AppCompatActivity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.view1);
webView.loadUrl("https://comm100.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
// popup webview!
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
final WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
newWebView.getSettings().setSupportMultipleWindows(true);
newWebView.getSettings().setDomStorageEnabled(true);
newWebView.getSettings().setAllowFileAccess(true);
newWebView.getSettings().setAllowContentAccess(true);
newWebView.getSettings().setAllowFileAccessFromFileURLs(true);
newWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
newWebView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); //making sure the popup opens full screen
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
newWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
if (newWebView !=null){
webView.removeView(newWebView);
}
}
});
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
answered Nov 27 '18 at 11:21
J. DoeJ. Doe
165
165
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393002%2fwebview-not-closing-onclosewindow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
