Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download script using Titanium API
<html>
<head></head>
<body style="background-color:#1c1c1c;margin:0">
<div style="border-top:1px solid #404040">
<div style="color:#fff;;padding:10px">Welcome to Titanium</div>
</div>
<script type="text/javascript">
var url = 'http://www.codeboxed.com';
// Initialize the HTTPClient object
var httpClient = Titanium.Network.createHTTPClient();
// Connect to the url above
if (httpClient.open('GET', url)) {
// Create the temporary file
var file = Titanium.Filesystem.createTempFile();
// Set the path to desktop directory in our case
var filePath = Titanium.Filesystem.getDesktopDirectory().toString()+
Titanium.Filesystem.getSeparator()+
'index.html';
// Copy the temporary file to our path
file.copy(filePath);
// Handle the reveived data (Titanium.Filesystem.File can also be used as a handler)
httpClient.receive(function(data) {
var file = Titanium.Filesystem.getFile(window['filePath']);
// Open the file created before and write to it the received data
var fileStream = file.open(Titanium.Filesystem.MODE_APPEND);
fileStream.write(data);
fileStream.close();
});
} else {
Titanium.API.info('cannot open connection');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.