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
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.
-
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.