defining Navbar action as javascript doesn't work

V Vishal Bhatia 3 years 6 months ago
3 1 0

Hi all

I am trying to use a Navbar control and defining one of its actions to call a javascript method. Although, the method doesn't seem to get called. Here is the snippet

function myMethod(){
alert('clicked');
}

Rho.Navbar.create({
      left : {
        label  : "Home",
        action : "Example Domain"
      },
      right: {
        label  : "Actions",
        action : "javascript: myMethod();"
      },
      title : "Hello app"
    });

Although, if I just put the alert as an action instead of calling a method, it works', so this works
Rho.Navbar.create({
      left : {
        label  : "Home",
        action : "Example Domain"
      },
      right: {
        label  : "Actions",
        action : "javascript: alert('called')"
      },
      title : "Hello app"
    });

Any suggestions much appreciated.

Thanks
Vishal

Please Register or Login to post a reply

1 Replies

J Jon Tara

Using javascript alert() is a really bad idea. It stops the WebView cold in it's tracks until you close the alert.

I try not to use javascript alert() for debugging, or for anything else. It can break your code that works. And it can miraculously "fix" your code that doesn't work!

If you need to do some Javascript debugging, you can remote-debug with a desktop browser for either iOS (use desktop Safari on OS X) or Android (use desktop Chrome, but only with very new Android versions, I think only 4.4+).

IMO, it is better to learn some Ruby and write code like this (e.g. creating a Rhodes native NavBar)  in a Ruby controller. Some may disagree, but the Javascript support in Rhodes is just a nice crutch in case you don't want to learn Ruby. It has many downsides. This is one. It adds an unnecessary layer of complication

CONTACT
Can’t find what you’re looking for?