Discussion Forums  >  WebViews and HTML for Mobile

Replies: 3    Views: 214

McAppy
Lost but trying
Profile
Posts: 82
Reg: Nov 28, 2011
Perth, WA
3,020
02/15/12 01:16 AM (13 years ago)

Java scripts not working in Custom URL Webpages

I am using a Custom URL Webpage that contains java scripts for functions such as pop up alert boxes. On an android device, while the web site functions ok within the app, none of the java functions work. However the javascript functions work ok when used directly on the mobile browser. (Here's a simple sample link I used to test http://www.crowderassoc.com/javascript/confirm.htm - click on the Hot Web site button - the pop up does not works when using this link as a Custom URL Webpage in a Buzztouch app (v1.4.or 1.5) but works in the mobile browser.) Would there be a problem with my Eclipse or android SDK setup?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
02/15/12 01:35 AM (13 years ago)
could be all sorts of things. It's hard for some folks to get their heads around the idea that the built in browser that devlepers can use (you and us) is NOT the same thing as the Browser app on device. Think of it this way, the Browser that ships with an Android phone is a full-blown application, not just a window that rendered HTML. So, knowing that, sometimes it's tricky to get the build in browser widget that's in your code to work exactly like you would expect. There are some cases where you cannot get it to work at all (depending on the complexities of what you're trying to do). In most cases it will work. The file that handles the browser type screen is BT_screen_webView.java (assuming v1.5 here but v1.4 works nearly the same way, different file name though). Open this file in Eclipse and have a look at the lines starting around 116. You'll see some WebView configuration option such as webView.getSettings().setJavaScriptEnabled(true); These are the values you may need to tinker with (again, depends on lots of factors). If you can't get anywhere, you could always Google 'android web view javascript' or something. Lastly, the javascript itself, where is it? External file? Local in the HTML itself? A totally different URL? All this is related and you'll need to sleuth out the issue. You'll be enlightened one way or another when you get it working ;-)
 
McAppy
Lost but trying
Profile
Posts: 82
Reg: Nov 28, 2011
Perth, WA
3,020
like
02/15/12 04:23 AM (13 years ago)
thanks for the tips David. based on your suggested google searching, here's my fix which got the alert pop up boxes working for V1.4: in file Screen_CustomURL.java (...src/com/v1.4/BC.../com/ ) added the following lines in the appropriate areas : - import android.webkit.WebChromeClient; - browser.setWebChromeClient(new WebChromeClient()); Note: WebChromeClient seemed to be already set up in Screen_CustomHTML.java
 
CodeBuster
I hate code!
Profile
Posts: 26
Reg: Jan 04, 2012
Bedford, TX
10,260
like
04/10/12 12:28 PM (13 years ago)
For Android V1.5 the following seems to work: Add to import list: import android.webkit.WebChromeClient; Around line 120 in BT_screen_webView.java you will find a line that reads: webView.setWebViewClient(new WebViewClient(){ Before this line insert: webView.setWebChromeClient(new WebChromeClient()); Both alerts and confirms work. As a tip, hold your cursor over 'WebView' in the definition of webview just above the inserted line mentioned above for a great insight into how WebView works and what is needed. For cross device application support, I would suggest that the buzzTouch webview in android should be constructed in such a way as to be equivalent in function to that found in IOS including Javascript support and HTTP cookie handling.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.