简体   繁体   中英

How would I check if browser is using Javascript?

I'm attempting to write a method to see if the user has Javascript enabled in my custom browser app I'm making, if so then on my browser settings DialogFragment have the switch update onCreate to disabled or enabled, depending if Javascript is enabled or disabled for my webview.

I would assume I would use getSettings().getJavaScriptEnabled(); on webview in the method, but found no more documentation on it. How would I go about writing a method to check this?

you can only programatically change if your WebView´s javascript is enabled or disabled, so you are supossing to know the status.

private static boolean jsEnabled; 

//enable javascript
webSettings.setJavaScriptEnabled(true);
jsEnabled = true;

//disable javascript    
webSettings.setJavaScriptEnabled(false);
jsEnabled = false;

use the boolean variable jsEnabled to know the status of your webview´s javascript

or use the method getJavaScriptEnabled()

getJavaScriptEnabled() : Returns true if JavaScript is enabled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM