3 Replies Latest reply on Feb 21, 2014 4:08 AM by Jochem Pouwels

    WebView.navigate breaks javascript?

    Jochem Pouwels

      My application has multiple tabs

      Whenever I use a WebView.navigate() in my application, all the javascript on that same tab does not work anymore. What could be the problem?

       

      <script>
      function test()
      {
        alert(1);
      }
      </script>
      

       

      For example when every page in my application

      has a test button to show an alert with onClick

      a nextpage button that redirects to a new page with the changePage function of JQM

      and a firstpage button that redirects to a function that uses a WebView.navigate in the callback to navigate to the first page.

       

      First page:

      Click on test button -> alert appears

      Click on nextpage button -> next page appears

       

      2nd page:

      Click on test button -> alert appears

      Click on nextpage button -> next page appears

       

      3rd page:

      Click on test button -> alert appears

      Click on firstpage button -> first page appears (with WebView.navigate())

       

      First page:

      Click on test button -> nothing happens

      Click on nextpage button -> next page appears

       

      2nd Page:

      Click on test button -> nothing happens

      ........

        • Re: WebView.navigate breaks javascript?
          BHAKTA RANJAN SATAPATHY

          Hi ,

           

          Will below method work for you ?

           

          <div data-role="page" id="pageone">

          <script>

          $('#pageone').on( "pageshow", function( event, ui ) {

               function test()  {

                    alert("1"); 

               }

              });

          </script>

          </div>

          <div data-role="page" id="pagetwo">

          <script>

          $('#pagetwo').on( "pageshow", function( event, ui ) {

               function test()  {

                    alert("2"); 

               }

              });

          </script>

          </div>

           

          Thanks

            • Re: WebView.navigate breaks javascript?
              Jochem Pouwels

              Hey,

              I think I got it fixed now by replacing WebView.navigate(.....) by WebView.executeJavascript("$.mobile.changePage(......)"). (It even supports transitions after a callback )

              If I find anything else that breaks because of this i'll give feedback on here and try your code.

               

              Thx

                • Re: WebView.navigate breaks javascript?
                  Jochem Pouwels

                  Well almost everything works now, but I cant seem to get it to work in one situation.

                  In my app users can buy certain items, after the user clicks on the "pay" button the app redirects to an external url (it stays within the app but it loads something like http://www.youcanpayhere.com/?afterpayurl=xxx).

                   

                  Normally I redirect this with WebView.navigate and with the parameter  "after pay url" the site knows what url it should redirect again to return in the app

                  (url will be something like: IPADRES/App/Order/index)

                   

                  Is there any other way so I dont have to use WebView.navigate to load an external url within my app? $.mobile.changePage or loadPage does not work.