Web Popups

This is a continuation of the discussion from the API page. [import]uid: 7559 topic_id: 24287 reply_id: 324287[/import]

I’m a big fan of Corona, and love working in Lua. Lately, I’m finding the web-popup and potential integration with Corona code quite exciting.

Even Ansca’s promotional pages talk about HTML5/OpenGL integration. That’s a *bit* of a stretch, though, isn’t it?

From what I can tell, interaction between the loaded page and the LUA code is quite minimal:

  • The lua code can know when URL’s are being clicked, and can intercept them.

But that’s about it. There is no default mechanism to pass info *into* the web popup, nor to have finer interaction from the popup.

It’d be nice to have some API where JavaScript in the webpopup can communicate back and forth with lua to a greater degree.

To truly have two way communication between the two (HTML popup and lua code), I can only see a couple of options, currently:

  • Create custom html files on the fly, and load these with the web popup. This would be quite a crude way to pass in data to the webpopup.

  • Pass in custom data to the webpopup via arguments, and have JavaScript parse up the URL. Again, doable, but a bit of a pain on the JS side.

Both of those would only work for initial passing in of data/arguments, and aren’t dynamic at all.

Another option:

  • Write a local web server in Corona, and have AJAX JavaScript communicate back and forth with LUA this way.

This latter option *should* work well, although the complexity of requiring a web server in your code, is a major drawback, along with all the parsing.

(I have most of the web server code I need already written, but again, it seems like a long way to go to share some data with the web popup.)

If Corona could offer something a bit slicker along these lines, I think it would go a long way to making interactive HTML5 work alongside lua code and OpenGL objects.

It’d be the difference between the value of a pop-up static web page, and true interactive HTML5Corona/OpenGL integration.

Or am I missing something obvious?

(Is it even possible for Ansca to add some functionality to address this, short of adding a AJAX/webserver gateway between the two?)

-d [import]uid: 40450 topic_id: 24287 reply_id: 98865[/import]

+1 for javascript lua communication
[import]uid: 123747 topic_id: 24287 reply_id: 98936[/import]

dale: I agree with you! Just a few comments

- Pass in custom data to the webpopup via arguments, and have JavaScript parse up the URL. Again, doable, but a bit of a pain on the JS side.

This suggestion will not work for all scenarios. The URL bug present in Honeycomb and ICS will make you miserable.

- Create custom html files on the fly, and load these with the web popup. This would be quite a crude way to pass in data to the webpopup.

I couldn’t agree more with you!!

- Write a local web server in Corona, and have AJAX JavaScript communicate back and forth with LUA this way.

This was the option that actually solved my problem. Clean and open doors for more advance features. [import]uid: 45445 topic_id: 24287 reply_id: 102679[/import]

There is a bug for web popup.
The popup windows is twice the size as I expected on iPhone retina.
This bug exists both in device and ios simulator.
My corona version is 2012.781 [import]uid: 35642 topic_id: 24287 reply_id: 102862[/import]

My logic like this:

show a menu.html, there are many href on the page. touch anyone url, listener will be get the message and make special doc.html and showWebPopup.

My code like this:
1, showWebPopup(“menu.html”, opt1);
2, listener to get URL and create doc.html and put special content inside.
3, cancelWebPopup();
4, showWebPopup(“doc.html”, opt2);

but when href was click and before cancelWebPopup, webpopup will show the [Web page not available] on android mobile device. and then close and open the doc.html.

the Web page not availabe page just show short time, but it’s bad for my app. How can I disable the [Web page not available] page to show?
Thanks.
[import]uid: 38309 topic_id: 24287 reply_id: 104155[/import]

I try to use AJAX on Web popup, but it still doesn’t work.

xmlhttp = new XMLHttpRequest();
xmlhttp.open(‘GET’, ‘open:’ + val, true);
xmlhttp.send();

I test the javascript on PC, the javascript can work well.

but in Corona SDK: Listener func(), I can not catch the URL for ‘open:xxx’.
Please help~
[import]uid: 38309 topic_id: 24287 reply_id: 104350[/import]

@shawnzhang: maybe this post can help you

http://www.think-techie.com/2012/05/corona-sdk-how-to-communicate-between.html

Regards, [import]uid: 45445 topic_id: 24287 reply_id: 104387[/import]

My app sends a POST request to my server, and gets an XML response. I can parse the XML and build an HTML String on the fly, but how do I send that to a Web Popup? I’m hoping you won’t tell me I have to write to a file first… that seems kind of unnecessary.

Does the Corona SDK support sending an HTML string directly to a web popup, or should I be using some other API? [import]uid: 38190 topic_id: 24287 reply_id: 104783[/import]

@aardwolf, there is no direct HTML string support for webPopups (or webView). You need to write it to a temporary file first. [import]uid: 7559 topic_id: 24287 reply_id: 104798[/import]

Nevermind on what I had written here… I thought it wouldn’t create a file because I was using:

[lua]local wfilePath = system.pathForFile( “tempShare.html” , “system.TemporaryDirectory”)[/lua]

instead of:

[lua]local wfilePath = system.pathForFile( “tempShare.html” , system.TemporaryDirectory)[/lua] [import]uid: 38190 topic_id: 24287 reply_id: 104887[/import]

Is there a limit to how big an HTML file can be? I’ve got my app generating an HTML file in the tmp folder. When I look at the file locally, everything is there. The web popup seems to truncate the results at around line 197. All of the html is pretty straightforward… no broken HTML tags or anything. [import]uid: 38190 topic_id: 24287 reply_id: 104901[/import]

I haven’t heard of any problem with it truncating content if the HTML code is valid. What device are you seeing this on? [import]uid: 7559 topic_id: 24287 reply_id: 104921[/import]

It’s happening in the Simulator as well as a Dell Streak 7 running Android 3.2. [import]uid: 38190 topic_id: 24287 reply_id: 104923[/import]

Apparently the HTML wasn’t technically valid…

This was the error:

<font color="#E9FFC7">

And this works fine:
<font color='\"#E9FFC7\"'>

What I find odd is that the HTML engine still colored the font appropriately, up until it just decided to quit processing it. [import]uid: 38190 topic_id: 24287 reply_id: 104928[/import]

I’m glad you found the problem. Sometimes it’s the little things that drive you crazy. :slight_smile: [import]uid: 7559 topic_id: 24287 reply_id: 104967[/import]

I thought that was it, but the issue is back. This time, it stops loading halfway through in the Simulator. When I open the HTML file directly in Firefox and examine the source, everything is fine.

When I actually build it and run it on my Android device, it works. [import]uid: 38190 topic_id: 24287 reply_id: 104971[/import]

@aardwolf Testing with Firefox is not the best way to go. It may work with firefox but it may not work with Safari or Chrome. In your case, try to use Chrome and debug your page code by pressing cmd+alt+j (in OSX, sorry don’t remember the shortcut in Windows). Most likely your page has errors. [import]uid: 45445 topic_id: 24287 reply_id: 104975[/import]

@aardwolf, I got same problem!

by the way. I hope corona sdk can support Jquery-mobile on WebPopup.

[communicate between Javascript and Lua runtime]

If can do that, I think we can make a lot of applications use this engine. [import]uid: 38309 topic_id: 24287 reply_id: 104979[/import]

I’ve spent quite a bit of time trying to track this down. I find it VERY interesting that the page truncates right at a total of 8192 characters (2^13)… [import]uid: 38190 topic_id: 24287 reply_id: 104982[/import]