4 Replies Latest reply on Apr 16, 2013 12:16 PM by Kutir Mobility

    Control WebView from controller actions

      Hi All,

      I am Newbie to RhoMobile, trying tutorial for "Control WebView from controller actions"  (http://docs.rhomobile.com/rhodes/ui).

      Can u please help me out how to open any webPage from application.rb? I want to open any webPage suppose google page?

       

      I tried onload/windows.location/

      System.open_url. But didn't find the correct approach.

       

      Please help me out

        • Re: Control WebView from controller actions
          Darryn Campbell

          Hi,

           

          To navigate to a webpage from your controller you can use the WebView API (http://docs.rhomobile.com/rhodesapi/webview-api#navigate) and call webview.navigate.  It does sound like you just want to redirect your view to a different webpage, in which case I'd suggest adding the window.href to your index.erb:

          <script language="JavaScript">
            window.location.href = "SpecRunner.html";
          </script>
          

           

          Regards.

            • Re: Control WebView from controller actions

              Thanks Darryn;

               

              I tried this. and it is working but it is redirecting to html page.

               

              <button onclick="onclickButton()">new method</button>

                    <script language="JavaScript"> 

                    function onclickButton() {

                      window.location.href = "newPage.html";

                    

                    } 

                    </script>

               

              When I tried to open window.location.href = "http://www.google.com; , it shows me nothing...

              1 of 1 people found this helpful
                • Re: Control WebView from controller actions

                  There is a semi-colon included at the end of your url string, still inside the quote probably, that could be a typo error that causing the issue. Kindly  check your code again.

                  1 of 1 people found this helpful
                  • Re: Control WebView from controller actions
                    Kutir Mobility

                    Hi Ankur

                     

                    Setting the location in window.location is fine, but then the form is submitted, which will reload the current page instead.

                    Return false from the method as

                     

                    <script type="text/javascript">

                                          

                                                 function onclickButton() {

                                          

                                                   window.location.href="http://www.google.co.in";

                                                   return false;

                                                                                

                                                                        

                                                 }

                                          

                                                 </script>

                     

                    Return false will stop the default action of the event

                     

                    Hope it helps

                     

                    Thanks

                    Dhepthi

                    Kutir Mobility