How to use Corona Lua code/Function in javascript/Html?

Hi,

I want to use particular code block in java script

i have tried with this like

function callbackFunc1()

          {

            console.log(“This is my test log”);

]]…print(“This is my inside java fun()”)…[[

            }

          

      

  var infowindow]]…i…[[ = new google.maps.InfoWindow({

                                                             content: “<strong>]]…product_list[i].nome…[[</strong>]]…product_list[i].categoria…[[<br/>]]…product_list[i].address…[[<input type=‘button’ onClick=‘callbackFunc1()’/>]]…[[”,

                                                             maxWidth: 150,

                                                                                        autoScroll:true,

                                                             disableAutoPan : true

                                                             });

But its not working,

So please guide me how can I use corona code into java script?

Thanks

You said it’s not working – what’s happening instead?  Your code is dynamically generating a block of Javascript – have you checked that the Javascript you’re generating is in fact valid?

  • Andrew

I want an click event navigation on marker, If user click on any marker from google map , then I want to open new lua storyboard view, but I am having problem in navigating in jS to corona lua code
I already tried with lua.vm.js and lua.js
here is my code block for the same\

var infowindow]]…i…[[=]]…storyboard.gotoScene( “mod_menu”, “fromBottom”, 500 )…[[

i am just trying to open view above code in java script but its not working and throwing error

Thanks,
Kirti

OK, I think I follow you.  You want something that the user does within the webView (in your case, clicking a Google Maps marker) to cause something else to happen in Corona outside of the webView (in your case, going to a different storyboard scene).

There’s no way to directly call Lua/Corona code from Javascript or HTML.  That’s because the web page is running in its own mini web browswer environment – in a sense, the page doesn’t even know Lua/Corona exists.

But, there is an indirect way to call Lua/Corona code from Javascript or HTML, which Corona was designed to let you do.  You do it by setting up a urlRequest event listener on your webView, and you listen for custom URLs you try to ‘open’ in your webView.

Basically, it looks like this.  Here’s some HTML with Javascript:

\<html\> \<head\>\</head\> \<body\> &nbsp; \<script type="text/javascript"\>window.open("LAUNCHED")\</script\> &nbsp; \<a href="CLICKED"\>Try clicking me\</a\> &nbsp; \</body\> \</html\>

If you open this page in a webView and set up a urlRequest listener on it (see the bottom of this API page for an example: http://docs.coronalabs.com/daily/api/library/native/newWebView.html), your listener will receive urlRequest events (http://docs.coronalabs.com/daily/api/event/urlRequest/index.html) where event.url is “LAUNCHED” or “CLICKED”.  Thus, your Lua/Corona code will know that something happened in side the webView and can act accordingly.

  • Andrew

Very useful, thanks for sharing.

You could modify the code downloadable here: http://forums.coronalabs.com/topic/38584-custom-map-markers-with-buttons/ to suit your needs! Simply change what happens in the event listener to call a new scene instead of an alert.

Thanks a lot, i was searching this solution since 4 days, thanks all for you reply, It working for me also and very great help here 

You said it’s not working – what’s happening instead?  Your code is dynamically generating a block of Javascript – have you checked that the Javascript you’re generating is in fact valid?

  • Andrew

I want an click event navigation on marker, If user click on any marker from google map , then I want to open new lua storyboard view, but I am having problem in navigating in jS to corona lua code
I already tried with lua.vm.js and lua.js
here is my code block for the same\

var infowindow]]…i…[[=]]…storyboard.gotoScene( “mod_menu”, “fromBottom”, 500 )…[[

i am just trying to open view above code in java script but its not working and throwing error

Thanks,
Kirti

OK, I think I follow you.  You want something that the user does within the webView (in your case, clicking a Google Maps marker) to cause something else to happen in Corona outside of the webView (in your case, going to a different storyboard scene).

There’s no way to directly call Lua/Corona code from Javascript or HTML.  That’s because the web page is running in its own mini web browswer environment – in a sense, the page doesn’t even know Lua/Corona exists.

But, there is an indirect way to call Lua/Corona code from Javascript or HTML, which Corona was designed to let you do.  You do it by setting up a urlRequest event listener on your webView, and you listen for custom URLs you try to ‘open’ in your webView.

Basically, it looks like this.  Here’s some HTML with Javascript:

\<html\> \<head\>\</head\> \<body\> &nbsp; \<script type="text/javascript"\>window.open("LAUNCHED")\</script\> &nbsp; \<a href="CLICKED"\>Try clicking me\</a\> &nbsp; \</body\> \</html\>

If you open this page in a webView and set up a urlRequest listener on it (see the bottom of this API page for an example: http://docs.coronalabs.com/daily/api/library/native/newWebView.html), your listener will receive urlRequest events (http://docs.coronalabs.com/daily/api/event/urlRequest/index.html) where event.url is “LAUNCHED” or “CLICKED”.  Thus, your Lua/Corona code will know that something happened in side the webView and can act accordingly.

  • Andrew

Very useful, thanks for sharing.

You could modify the code downloadable here: http://forums.coronalabs.com/topic/38584-custom-map-markers-with-buttons/ to suit your needs! Simply change what happens in the event listener to call a new scene instead of an alert.

Thanks a lot, i was searching this solution since 4 days, thanks all for you reply, It working for me also and very great help here