function getFavicon (url) {
// here we pull out only the part we need from the url string - domain name
var domain = id.match (/ (\ w +): \ / \ / ([^ \ /:] +) (: \ d *)? ([^ #] *) / i);
if (domain! = null) {
var domname = domain [2];
// check if we already have such an icon in the cache
var file = air.File.applicationStorageDirectory.resolvePath ("favicons /" + domname + '.png');
if (file.exists)
// and, if there is, return a link to it
return file.url;
// but if not, send a request for sectorprime
var fav = "http://www.sectorprime.com/cgi-bin/fav2png.pl?fav=" + domname;
air.trace ('load favicon' + domname);
var request = new air.URLRequest (fav);
var loader = new air.URLLoader </a> ();
// important! we will receive data in binary form
loader.dataFormat = air.URLLoaderDataFormat.BINARY;
loader.addEventListener (air.Event.COMPLETE, function (e) {
// this function will work out immediately after we receive the answer to the request
var loader = e.target;
// create a stream to write to the file
var fileStream = new air.FileStream ();
fileStream.open (file, air.FileMode.WRITE);
// and write everything we got into it
fileStream.writeBytes (loader.data);
fileStream.close ();
});
// actually start the boot process
loader.load (request);
}
// but this icon will be issued by us by default
return "/images/icon_item.png";
} var favdir = air.File.applicationStorageDirectory.resolvePath ("favicons");
// find out if such a folder exists at all
if ((favdir.exists) && (favdir.isDirectory))
// if exists, delete the folder along with the contents
favdir.deleteDirectory (true); Source: https://habr.com/ru/post/27435/
All Articles