How can i achieve load event of a window? What i want is , i have a remote data connected for advertisement, so i want to display ads on home screen when the app.js is opened. i want to call a function on window open/load that fetches the remote data. thanks
2 Answers
Hello, You can do code in open event listener of window.
Win.addEventListener("open",function(){ alert("onload"); // Preform network task here.... ActInd = Titanium.UI.createActivityIndicator({ height:50, message:"Requesting..", width:10 }); ActInd.show(); var xhr = Titanium.Network.createHTTPClient(); xhr.ondatastream = function(e) { Titanium.UI.currentWindow.add(ActInd ); }; xhr.onload = function() { // Data comes in this block so after finishing you may hid indicator ActInd.hide(); } xhr.onerror = function(e) { Ti.API.info("error = " + e.error); ActInd.hide(); var alertDialog = Titanium.UI.createAlertDialog({ message: 'Sorry No Network !', buttonNames: ['OK',''] }); alertDialog.show(); }; xhr.open('POST','https://www.your string); xhr.setTimeout(20000); xhr.send(SendRequest); });
Not working :( no popup occurred , Well, let me mention i am working on Mobile Web application so is there any change occur in load event. thanks
Your Answer
Think you can help? Login to answer this question!