Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android WebView crashes on AddEventListener

Adding the following to the Webview seems to crash it on Android. Anyone had any success with it? or is it a known bug?

This means I will have to recreate my HTML over an over again to update it?

Ti SDK: 1.8.1
Platform: Android
Version: 2.3.3
Device/Emulator: emulator
Developing on: OSX

var html = '<html>' +
        '<head><meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable=no;" />' +
        '<style>' +
        '   body {font-family:Arial Rounded MT Bold, Arial; font-size:14px;}' +
        '   p {font-family:Arial Rounded MT Bold, Arial; font-size:14px;}' +
        '</style></head>' +
        '<body>' +
        '<div id="test">No Event</div>' + 
        '<script type="text/javascript">' +
     'Ti.App.addEventListener(\'SomethingStrange\', function(e) { ' +
        '   document.getElementById( \'test\' ).innerHTML = \'Got the event\';' +
        '});' +
        '</script>' +
        '</body>' +
        '</html>';

        var webview = Ti.UI.createWebView({
            top: 0,
            left: 0,
            backgroundColor: '#ffffff',
            scalesPageToFit: true,
            html: html
        });
— asked February 5th 2012 by Kouroche Sedaghatian
  • android
  • ti 1.8.1
  • webview
1 Comment
  • evalJS also seems to crash it, and the same issue exists on 1.8.0.1

    — commented February 5th 2012 by Kouroche Sedaghatian

2 Answers

  • Hi have you tried saving the html code in inside the HTML page and then loading it in the web-view? Give that a try might it solve the problem.

    Regards

    Nikunj

    — answered February 6th 2012 by Nikunj Sakhrelia
    permalink
    1 Comment
    • Tried that too. That seems to crash it even without the addEventListener bit.

      — commented February 6th 2012 by Kouroche Sedaghatian
  • there is a bug with android 2.3.3 with webview event within simulator, but it's fine when you publish in really device (android 2.3.3), so you can use android 4.0 for testing with the simulator

    — answered August 24th 2012 by Winson Qiu
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.