Created
November 27, 2011 06:15
-
-
Save soemarko/1397078 to your computer and use it in GitHub Desktop.
Using webview to use prompt window with Titanium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var btn = Ti.UI.createButton({ | |
title: 'Prompt!', | |
height: 40, | |
width: 100, | |
top: 20 | |
}); | |
var lbl = Ti.UI.createLabel({ | |
text: 'Label', | |
textAlign: 'center' | |
}); | |
var wv = Ti.UI.createWebView({ | |
url: 'prompt.html', | |
visible: false | |
}); | |
var win = Ti.UI.createWindow({ | |
backgroundColor: '#cecece', | |
title: 'Window' | |
}); | |
win.add(btn); | |
win.add(lbl); | |
win.add(wv); | |
btn.addEventListener('click', function(e) { | |
wv.evalJS('doPrompt()'); | |
}); | |
Ti.App.addEventListener('app:prompt', function(e) { | |
lbl.text = 'prompt> ' + e.data; | |
}); | |
win.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Prompt!</title> | |
<script> | |
function doPrompt() { | |
var x = prompt('Question for prompt:'); | |
if(x && x != '') { /* ignoring 'Cancel' or empty string */ | |
Ti.App.fireEvent('app:prompt', {data: x}); | |
} | |
} | |
</script> | |
</head> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for this !
i made a function out of it (which is independant and doesn't have the "prompt.html" title on the dialog) :