Alternate Solution for setJavaScriptEnabled(true);

Vigbyor picture Vigbyor · Nov 22, 2013 · Viewed 20.2k times · Source

I have developed an Android Application which uses Webview Component. I have used following line into my code,

webViewScores.getSettings().setJavaScriptEnabled(true);

Due to this line it is showing Lint warning as Using setJavaScriptEnabled can introduce XSS vulnerabilities into you application, review carefully. Now I know that I can suppress this warning by writing this line @SuppressLint("SetJavaScriptEnabled") above my method or at class level. But my question is, Is there any alternate solution for this ? I means is there any other way we can set Java Script Enabled in Webview ?

Answer

Neha Shukla picture Neha Shukla · May 19, 2014

you have to use it at Class Level like

@SuppressLint("SetJavaScriptEnabled")
public class MyActivity extends Activity
{
    ...
}

and according to me there is no other way to enable JavaScript in WebView and if your app really doesn’t require JavaScript usage within a WebView then don’t call setJavaScriptEnabled(true).