javascript - Inject code in inApp browser and get it's return value in the app -


i writing phonegap app, that's starting web app inside inappbrowser. feedback web app use further in phonegap app.

so user starts web app, things there , upon clicking button, web app returns value phonegap app.

i thought use executescript method of inappbrowser inject function, called inside web app using event, , when function called, evaluate return value inside web app. found not complete documentation of phonegap , question on stackoverflow: augmenting webapp native capabilities - bridging phonegap's inappbrowser rails web app application javascript

sadly not work expected, because callback function fires imediately, without waiting injected function execute.

here mobile app code

<!doctype html> <html>   <head>     <title>inappbrowser.executescript example</title>      <script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>     <script type="text/javascript" charset="utf-8">      // wait cordova load     //     document.addeventlistener("deviceready", ondeviceready, false);      // global inappbrowser reference     var iabref = null;      // inject our custom javascript inappbrowser window     //     function addfeebackfunction() {         iabref.executescript(             {code: "var evaluatefeedback = function(){return 'done';};"},             function(data) {                 alert(data);             }         );         //iabref.close();     }      function iabclose(event) {          iabref.removeeventlistener('loadstop', addfeebackfunction);          iabref.removeeventlistener('exit', iabclose);     }      // cordova ready     //     function ondeviceready() {          iabref = window.open('http://{ipaddress}/test/', '_blank', 'location=no');          iabref.addeventlistener('loadstop', addfeebackfunction);          iabref.addeventlistener('exit', iabclose);     }      </script>   </head>   <body>       <h1>mobile app</h1>   </body> </html> 

and web app code

<!doctype html> <html> <head>     <title>         test     </title>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">      <script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script>     <script type="text/javascript">         $(document).ready(function () {             $('#get-feedback').click(function() {                 var feedback = $('#feedback').val();                 evaluatefeedback(feedback);             });         });     </script> </head> <body> <div data-role="page">     <article data-role="content">         <h1>web app</h1>         <input type="text" id="feedback" /><br />         <button type="button" id="get-feedback">feedback</button>     </article> </div> </body> </html> 

just wild guess, you're not executing function...

{code: "var evaluatefeedback = function(){return 'done';};evaluatefeedback();"}

or better: {code: "'done';"}


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -