0 Replies Latest reply on Jul 13, 2012 1:35 PM by Steve Zhang

    WebView.execute_js issue

      Today I also found an issue of WebView.execute_js() method.

      I got the "error loading page" again, similar to one of my previous question:

      https://developer.motorolasolutions.com/message/4394#4394

       

      I feel it seems like the issue will happen if the page is defined like

      <div data-role="page">

      ..

      </div>

       

      Since the system-api-samples don't have this kind of page, and they are working.

       

      Following is my test code:

       

      index.erb

       

      <div data-role="page">

      <script type="text/javascript">

          function test() {

              alert("Javascript alert");

          }

       

       

          function test_prompt() {

              prompt("Javascript prompt", "default value");

          }

         

          function getPage(url,execute)

          {

              if (window.XMLHttpRequest)

              {

                xmlhttp=new XMLHttpRequest();

       

       

                xmlhttp.open("GET",url,false);

                xmlhttp.send(null);

                if (xmlhttp.responseText != null)

                {

                  if(execute) { return eval('(' + xmlhttp.responseText + ')'); }

                }

              }

              return -1;

          }

       

       

          function test_ajax() {

              return getPage('/app/SystemTest/show_alert',false);

          }

         

          function show_cookie() {

                  alert(document.cookie);

          }

       

       

      </script>

       

       

        <div data-role="header" data-position="inline">

         <h1>Test Refresh</h1> 

        </div>

       

        <div data-role="content">

         <ul>

          <li>

            <a href="<%= url_for :action => :refresh%>">refresh</a>

          </li>

          

           <li>

              <a href="<%= url_for :action => :exec_js%>">exec_js</a>

           </li>  

         </ul>    

        </div>

         

      </div>

       

       

      controller.erb

      require 'rho/rhocontroller'

       

       

      class WebViewController < Rho::RhoController

       

       

        def refresh

            WebView.refresh

        end

       

        def exec_js

           WebView.execute_js("test();")

        end

      end