capturing javascript alert prompt in native browser

13 views
Skip to first unread message

barr...@gmail.com

unread,
Nov 7, 2016, 6:21:08 AM11/7/16
to CodenameOne Discussions
I am using IntelliJ Idea to develop an custom eBook reader app which i expect to port to most platforms in the near future. This app makes use of both online shopping carts and support systems available to all from our website. The site works well and uses javascript alerts in several places. This has not been a problem until we attempted to launch the windows desktop build. Apparently the native browser component is not allowing the javascript alerts/confirms to be displayed.

My question. Is there something that I am supposed to do to capture this event and handle it via my java code? Everything seems to be pointing towards this JSObject library, but the site works well as is in the android build version. 

Thanks

Steve Hannah

unread,
Nov 7, 2016, 11:47:23 AM11/7/16
to codenameone...@googlegroups.com
Looks like onAlert isn't implemented in the JavaSE build.  The modal nature of it makes it tricker than other callbacks, but I have seen a few posts claiming to offer an implementation (e.g. https://gist.github.com/jewelsea/5614167) that we might be able to adopt.

Right now, on simulator, the alert('') method will fire a web event on the Browser component called "onMessage".  You can capture it with:

browserComponent.addWebEventListener("onMessage", e->{
     String message = (String)e.getSource();
     //  do something with the message, like show a dialog.
});

The trouble with this is that it is async (doesn't block javascript) so even if you do display a dialog here, it won't behave as you expect --- javascript execution will continue while your dialog is displayed.

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/5b516ed3-f034-407c-840e-8e35ac75a9fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One
Reply all
Reply to author
Forward
0 new messages