Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  90] [ 6]  / answers: 1 / hits: 27005  / 10 Years ago, tue, april 22, 2014, 12:00:00

Android 4.1
Eclipse
Testing on device



I am trying to open a html/javascript webpage, hosted on my localhost for now, in my android application through a webview.
The page is suppose to just close after 2 sec through the below code



<script type=text/javascript>
alert('hello');
setInterval(function(){window.close();},2000);
</script>


I am able to get the hello alert by using WebChromeClient. But the window.close is still not working. Any help would be appreciated.



PS: Here is how i am loading the URL:



WebSettings ws = webView.getSettings();
ws.setJavaScriptEnabled(true);
ws.setJavaScriptCanOpenWindowsAutomatically(true);
webView.loadUrl(http://192.168.1.137/abc.html);
webView.setWebChromeClient(new WebChromeClient());

More From » android

 Answers
44

Try this :



WebChromeClient webClient = new WebChromeClient(){

public void onCloseWindow(Window w){
super.onCloseWindow(w);
Log.d(TAG, Window close);
}
};


Description :



public void onCloseWindow (WebView window)


Notify the host application to close the given WebView and remove it from the view system if necessary. At this point, WebCore has stopped any loading in this window and has removed any cross-scripting ability in javascript.


[#71360] Saturday, April 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bobbyallanh

Total Points: 693
Total Questions: 120
Total Answers: 101

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;