Titanium Community Questions & Answer Archive

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

Create button on a webview with latest TI SDK

Hi all,

On a webview, with the old 0.9 TI SDK i created a button with listener directly in the .HTML as :

<body>
    <div id="index"></div>
    <script>
        var button = Titanium.UI.createButton({
            id:'index',
            backgroundImage:'images/index.png',
            height:480,
            width:320
        });

        button.addEventListener('click',function(e)
        {
            Titanium.UI.currentWindow.close();
        })
    </script>
</body>

And that worked..

But since i am under the 1.3 SDK, this javascript doesn't seems to work anymore.

So what is the right way now to do that thing ?

Best regards,
Yann

— asked June 17th 2010 by Yann Marzack
  • button
  • javascript
  • webview
0 Comments

2 Answers

  • Hey Yann

    I figured this one out. I was having the same problem. Now I'm not really a javascript pro or anything, so i can just tell you what I did, not really how it works hahah.

    I basically made a subwindow the same size as the webview I already had, as well as in the postition i wanted it. Then I added the webview to that subwindow and added the subwindow to second subwindow named w. After that, w is added to the main window (win).

    I then added the button to w instead of win like I had it at first.

    BEFORE

    win.add(ads);  //this is my button, a banner ad
    w.add(webweb); //this is the webview
    w.open();      //w is my first subwindow
    win.add(w);    // win is my main window
    

    AFTER

    //added another subwindow
    
    var subwindow = Ti.UI.createWindow({
        height:290,
        top:80,
        width:260
    //    borderColor:"red"
    });
    
    w.add(ads);      //changed win to w
    subwindow.add(webweb);    //added webview to second subwindow
    w.add(subwindow);         //added second subwindow to first subwindow
    w.open();                 
    win.add(w);
    

    I'm sure there is a little cleaner way of doing this but this worked for me at the moment.

    — answered June 25th 2010 by Jimmy Lesondak
    permalink
    0 Comments
  • Thanks for your reply.

    I think you could forget the subwindow.
    Just add your button to your webview.

    Things works for me :

    button = CreateButton
    win = Createwindow
    web = CreateWebView
    web.add(button)
    win.add(web)
    win.open()
    

    BUT !! as my webview can scroll vertically, i would like my button to scroll as too (like any standard button in any standard html page..)
    however when i create a button as you and i described, and if i set a top position when i create it, then it stay static over the webview scroll.

    — answered June 29th 2010 by Yann Marzack
    permalink
    1 Comment
    • Why don't you create a normal button in the webview and try to trigger a Titanium event when you click this button?
      It's easy to simulate the look of the button to be similar of a native one.

      — commented June 29th 2010 by Dan Tamas
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.