Android WebView Onjsalert Considerations

Source: Internet
Author: User
Tags stub

Recently, after using the Onjsalert method of WebView, I found that the HTML page clicked did not respond, the code is as follows:

Mwebview.setwebchromeclient (New Webchromeclient () {

			@Override public
			boolean Onjsalert (WebView view, String URL, String message,
					jsresult result) {
				
				if (message!=null) {
					
					//todo
					//Pop-up dialog
					Toast.maketext ( Getapplicationcontext (), message, Toast.length_long). Show ();
								
				return true;
			}

			@Override Public
			Boolean onjsconfirm (webview view, string URL,
					string message, jsresult result) {
				//TODO Auto-generated method stubs return
				super.onjsconfirm (view, URL, message, result);
			}

			@Override Public
			Boolean onjsprompt (webview view, string URL, String message,
					string defaultvalue, Jspromptresult result) {
				//TODO auto-generated method stub return
				super.onjsprompt (view, URL, message, DefaultValue, result);
			}
			
		);



Baffled, finally found the answer on the StackOverflow

Http://stackoverflow.com/questions/15892644/android-webview-after-onjsalert-not-responding-taps


Mwebview.setwebchromeclient (New Webchromeclient () {

			@Override public
			boolean Onjsalert (WebView view, String URL, String message,
					jsresult result) {
				
				if (message!=null) {
					
					//todo
					//Pop-up dialog
					Toast.maketext ( Getapplicationcontext (), message, Toast.length_long). Show ();
				
				Result.cancel ();	Be sure to cancel, otherwise there will be a variety of strange problems return
				true;
			}

			@Override Public
			Boolean onjsconfirm (webview view, string URL,
					string message, jsresult result) {
				//TODO Auto-generated method stubs return
				super.onjsconfirm (view, URL, message, result);
			}

			@Override Public
			Boolean onjsprompt (webview view, string URL, String message,
					string defaultvalue, Jspromptresult result) {
				//TODO auto-generated method stub return
				super.onjsprompt (view, URL, message, DefaultValue, result);
			}
			
		);


Return True and Result.cancel (); One can not be less, otherwise there will be a variety of strange problems.






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.