-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Javascript call from WebView to Android and Vice Versa #9
Comments
Wrap your javascript in a try catch block with the error method and see if anything prints. try{ That should log an error in eclipse if there's a javascript error somewhere. Good place to start. Aside from that, send me an example of your html content/custom js and I'll try and take a look. |
Thanks for replying, I have done what you said but still does nothing. <script type="text/javascript"> try{ prom(); }catch(err){ window.TextSelection.jsError(err); } function prom(){ alert("Function Click!"); } </script> Here's the mContextMenu.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() { public void onItemClick(QuickAction source, int pos, int actionId) { // TODO Auto-generated method stub if (actionId == 1) { // Do Button 1 stuff Log.i(TAG, "Hit Button 1: "); loadUrl("javascript: prom()"); // Here it is, I'm trying to call a javascript function on the html page provided } else if (actionId == 2) { // Do Button 2 stuff Log.i(TAG, "Hit Button 2"); } else if (actionId == 3) { // Do Button 3 stuff Log.i(TAG, "Hit Button 3"); } contextMenuVisible = false; } }); No error is being displayed in my Eclipse log cat from a WebView Tag category. Still I did tried pressing the button but the javascript function in my page wont trigger. Thanks in advance. |
I just had this problem too. If you're building for Android API 17 or greater you need to add the @JavascriptInterface annotation to the methods in TextSelectionJavascriptInterface, otherwise they're not available to the webview and the javascript fails with "TypeError: Object [Object] has no method 'setContentWidth'". |
Thanks for that. I just updated the class on the master branch with the @JavascriptInterface annotation. |
You're welcome, and thanks for the interesting demo. |
Good Day,
I have successfully executed this sample project using Eclipse, but i have this problem... When I add a simple button in the html file provided and attach an event to that button(I would like to call a javascript function), the javascript is not triggering.
Also, I tried to call a javascript function inside the
BTWebView
class at theOnActionItemClickListener
whenever an item is clicked, calling a javascript using this:this.loadUrl("javascript: testFunction();"); but it's not triggering.
Hope to hear from you Soon.
The text was updated successfully, but these errors were encountered: