Call Javascript function

How do I call javascript function from Corona Lua code?

Thank you

Unless you’re working with a native.newWebView(), Corona doesn’t support JavaScript. Corona uses Lua as a language.  We are adding support for HTML5 in the future at which point there will be some javascript support for HTML5 based apps, but for the current Corona, there isn’t any way to “call javascript”.

Rob

Hi Rob,

To play a youtube video channel, I created native.newWebView and then set iframe to define player. As youtube said, I set javascript to define stopvideo function to be called when device is turned off. So I need to call stopvideo when system suspended, How can I do that?

Thanks,

Bahman

I don’t know how successful you’re going to be with this.  Our webView’s were not designed to complex things. I don’t know if you can engineer your HTML to be caused using the :request() method in a way that wouldn’t reload the youtube video, but instead be able to pass in commands.  

Rob

Good Idea Rob.

I can setup youtube as pre default stopped.

Then on the suspended system event (Like pressing Power button),  set :request for webView.

So it will be started from scratch as pre default stopped.

It was what Google asked me for my app with youtube player and suspened my app based on player running after pressing power bottun!

Now, any time power button pressed to turn device off, I can catch event and call :reqest to stop the youtube video!

I’ll try it.

Thank you

Unless you’re working with a native.newWebView(), Corona doesn’t support JavaScript. Corona uses Lua as a language.  We are adding support for HTML5 in the future at which point there will be some javascript support for HTML5 based apps, but for the current Corona, there isn’t any way to “call javascript”.

Rob

Hi Rob,

To play a youtube video channel, I created native.newWebView and then set iframe to define player. As youtube said, I set javascript to define stopvideo function to be called when device is turned off. So I need to call stopvideo when system suspended, How can I do that?

Thanks,

Bahman

I don’t know how successful you’re going to be with this.  Our webView’s were not designed to complex things. I don’t know if you can engineer your HTML to be caused using the :request() method in a way that wouldn’t reload the youtube video, but instead be able to pass in commands.  

Rob

Good Idea Rob.

I can setup youtube as pre default stopped.

Then on the suspended system event (Like pressing Power button),  set :request for webView.

So it will be started from scratch as pre default stopped.

It was what Google asked me for my app with youtube player and suspened my app based on player running after pressing power bottun!

Now, any time power button pressed to turn device off, I can catch event and call :reqest to stop the youtube video!

I’ll try it.

Thank you