2 Replies Latest reply on Apr 17, 2013 12:35 AM by Kutir Mobility

    WebView.execute_js to work

      I'm trying to get WebView.execute_js("test();") It just can get it to show the popup welcome message at the launch of application. I get no error

      either:

       

      application.rb:

      class AppApplication < Rho::RhoApplication

        def initialize

          # Tab items are loaded left->right, @tabs[0] is leftmost tab in the tab-bar

          # Super must be called *after* settings @tabs!

          @tabs = nil

          #To remove default toolbar uncomment next line:

          #@@toolbar = nil

          super

       

          # Uncomment to set sync notification callback to /app/Settings/sync_notify.

          # SyncEngine::set_objectnotify_url("/app/Settings/sync_notify")

          SyncEngine.set_notification(-1, "/app/Settings/sync_notify", '')

        end

       

        def on_ui_cretaed

          WebView.execute_js("onload")

          super

        end

      end

       

      index.erb

      <div data-role="content">

       

            <script language="JavaScript"> 

            function onload() {

             alert("welcome")

           } 

            </script>

        </div>

       

      Please help me out

        • Re: WebView.execute_js to work

          the script on a page will be ready in the memory once the page is rendered, which happens after calling the controller that contains that start path. So you could still not call that javascript function on the on_ui_created hook method of AppApplication. Better to call that function in the controller method of your start path configured in rhoconfig.txt.

          1 of 1 people found this helpful
          • Re: WebView.execute_js to work
            Kutir Mobility

            Hi Ankur,

             

            There is a small typo in your method name "on_ui_cretaed"  it should be "on_ui_created".

            The javascript method "test" that you have kept in  the index.erb file won't be avaialble during on_ui_created method is called, when you call "super"  only then the start_path from rhoconfig.txt will be executed.

            Please refer http://docs.rhomobile.com/rhodes/application.

            If you want to call some javascript method on loading the UI you can use body "onLoad" method.

            <head>

            <script type="text/javascript">

                function test() {

                 alert("onload method called");

                }

               </script>

            </head>

            <body onLoad="test();">

            </body>

             

             

             

            Thanks

            Surendran S

            Kutir Mobility