5 Replies Latest reply on Feb 19, 2013 8:55 AM by Jonathan Chaalan

    Webview.navigate problems

      Hi Guys,

       

      I am using the latest Rhodes version (3.5.1.12)...

       

      I am building my project using jQuery mobile for the views, and now I am adding the functionality where a user can choose/capture an image, and then he can upload it. I read that in the Callbacks, I need to use WebView.navigate, so I am using it in the Camera Callback. However I noticed that when WebView.navigate is called, the view that is called will always remain in the DOM (or whatever it is when you see the elements in the inspector..), so even though I go out of the current page having the Image, in the inspector I still see the page that the WebView.navigate redirected me to.

      This is creating problems, because if I reopen the page, I will see the same page twice in the inspector, with the same elements and Ids, etc.. So now my code doesn't work anymore because it will not know what element to catch to apply things on, since the same IDs exist in both pages (1 that I just opened, and the other that is ALWAYS opened after the WebView.navigate has been called). Any ideas what I should do? Why is this happening?! Please help..

       

      Thanks,

      Jonathan

        • Re: Webview.navigate problems
          Robert Galvin

          This sounds like how jQuery is handling the transitions between pages. They usually keep one 'page' in the visible part of the dom and previous 'pages' in a hidden part of the DOM. You can go into the layout.erb and set jquery to not use Ajax.

           

          $.mobile.ajaxEnabled = false;
          
          • Re: Webview.navigate problems
            Robert Galvin

            You can use descendant selectors instead. JQM will put a class call 'ui-page-active' in the 'active page'. Then the second selector will be the class/id of the item on the page.

             

            $("div.ui-page-active .myelement")


            instead of just:


            $(".myelement")


            Hope this helps.

            1 of 1 people found this helpful
              • Re: Webview.navigate problems
                Jon Tara

                $.mobile.activePage is always a reference to the current page, so that is another option. $.mobile.activePage.find(".my-element") or $(".my-element", $.mobile.activePage) (find is faster).

                 

                You do not have to use WebView.navigate in callbacks unless you actually want to navigate somewhere.

                 

                It's really not a good idea to use IDs at all with jQuery Mobile. The problem is it loads multiple pages into the DOM, and it's not allowed to have multiple instances of the same ID in a document. The results with different browsers is unpredictable. NO browser can deal with the properly. The difference is how they deal with it improperly and make the best of invalid HTML. If you do use IDs, you should insure that each ID is unique across the entire application.

                 

                Especially for things like a photo-capture page, a map, etc. I find it best to just leave a page in the DOM, by using "data-dom-cache="true". If you navigate to that page, you will just navigate to the page that is already loaded. One caveat is that if you add a query string to the URL, then it's considered a different page and it will get loaded form the Rhodes server. Perhaps that is what is happening to you.

                1 of 1 people found this helpful