Titanium JIRA Archive
Appcelerator Community (AC)

[AC-756] WebView.evalJS does not return the correct value when the expression is suffixed by semicolon

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNeeds more info
Resolution Date2015-09-15T04:07:01.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterTitus Wiguno
AssigneeShak Hossain
Created2014-08-22T18:04:12.000+0000
Updated2016-03-08T07:37:01.000+0000

Description

I'm using social.js to make integrated social-network login to my app. Apparently this line in social.js (line 381 or so) prevented the twitter login to behave as it should: var response = e.source.evalJS('(p = document.getElementById("oauth_pin")) && p.innerHTML;'); I managed to work it out by removing the semicolon in the expression to eval.

Comments

  1. Shuo Liang 2014-08-25

    hi, I think you don't need a semicolon in string, Like the example in Document. Ref: [http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-method-evalJS] Regards, Shuo
  2. Rakhi Mitro 2015-08-30

    Hello, I have tested this issue in updated environment. [evalJS ](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-method-evalJS) function evaluates a JavaScript expression inside the context of the web view and optionally, returns a result.The JavaScript expression must be passed in as a I think you don't need a semicolon in string. This is not a bug for latest Appcelerator version. Not sure if this is still an issue for you. It doesn't appear to be based on our latest tests. Please let me know how I can help further. *Test Environments:* CLI Version :4.0.1 Titanium SDK Version:4.1.0.GA Android: Google Galaxy Nexus:4.1.1 - API 16 - 720x1280 Appc Studio: Appcelerator Studio, build: 4.1.1.201507141126 Alloy: 1.7.3 *Test code:* *app.js*
       
           var win = Titanium.UI.createWindow();
           var webview = Ti.UI.createWebView({
               url: 'test.html'
           });
           win.add(webview);
            
           webview.addEventListener('load',function(e) {
              
               var response = e.source.evalJS('(p = document.getElementById("oauth_pin")) && p.innerHTML;');       
               var response2 = e.source.evalJS('(p = document.getElementById("oauth_pin")) && p.innerHTML');
               Ti.API.info( "# of response with semicolon -> " + response.length  );
               Ti.API.info( "# of of response without semicolon -> " + response2.length  );
              
           });
           
           win.open();
         
       
    *test.html*
       
       <!DOCTYPE html>
       <html>
       <body>
       
       <h1>My First Heading</h1>
       
       <p id="oauth_pin">My first paragraph.</p>
       
       </body>
       </html>
       
       
    *Test Steps:*

    Create web view on app.js .

    Create a html page text.html .

    Add load event listener on window

    Call evalJS function into load event.

    Run the project

    *Test Result:* Project builds successfully .WebView.evalJS does return the correct value when the expression is not suffixed by semicolon and with semicolon it works as expected. *Ti logs:* [WARN] : EGL_genymotion: eglSurfaceAttrib not implemented [INFO] : # of response with semicolon -> 19 [INFO] : # of of response without semicolon -> 19 [INFO] : APSAnalyticsService: Analytics Service Started [INFO] : APSAnalyticsService: Stopping Analytics Service Thanks

JSON Source