Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView doesn't load jQuery

I'm making a webapp and I'm using jQuery.

I've made a simple android application with a WebView in it, and I load my url: www.mydomain.com

In mydomain.com I have:

<script src="js/jquery_1.4.2_min.js"></script> 

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
 alert("Hii!!!!");
});
</script>

If I visit mydomain from the browser, the alert shows fine. But If I visit from my native application, it doesn't show. What can I do?

like image 287
Klian Avatar asked Jul 19 '11 16:07

Klian


3 Answers

Is JavaScript enabled in your webview...?

WebView.getSettings().setJavaScriptEnabled(true);
like image 102
Torid Avatar answered Oct 18 '22 03:10

Torid


Old question, but thought i'd add my 2cents anyway.

Javascript alerts do work in a webview, but you have to set the Web chrome client first.

webView.setWebChromeClient(new WebChromeClient())
like image 20
Stimsoni Avatar answered Oct 18 '22 03:10

Stimsoni


I'm no expert with Android native but we have just developed an app using jQuery based site within a webview. You need setJavaScriptEnabled(true) in your activity class and jQuery runs jsut fine. However your example with alert('Hi'); will not work because Android webviews don't support alerts by default. It can be enabled with a little googling... http://lexandera.com/2009/01/adding-alert-support-to-a-webview/

Alternatively we added a custom showAlert js function to display pretty user notifications.

like image 5
Wade Avatar answered Oct 18 '22 03:10

Wade