Refresh Page upon tab click

You must Login before you can answer or comment on any questions.

Hi All

I am looking for a way to reload a page upon a tab click currently it just maintains the previous state i want it to completely close and reopen again.

I am a newbie at titanium so some help with this would be amazing.

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#fff');
var tabGroup = Titanium.UI.createTabGroup();
 
var musicPlayer = Titanium.UI.createWindow({
    title:'Music Player',
    url:'main_windows/player.js'
});
 
var MusicPlayerTab = Titanium.UI.createTab({
    title:"Music Player",
    window:musicPlayer
}); 
 
var musicSync = Titanium.UI.createWindow({
    title:'Sync',
    url:'main_windows/sync.js'
});
 
var musicSyncTab = Titanium.UI.createTab({
    title:'Sync',
    window:musicSync
});
 
tabGroup.addTab(MusicPlayerTab);
tabGroup.addTab(musicSyncTab);
tabGroup.open();
and player.js i have been trying to do the following but it doesnt work.
var win = Titanium.UI.currentWindow;
Ti.UI.currentTab.close(win);
Ti.UI.currentWindow.addEventListener('open', function(e) {
 
//code runs here???
 
});
so i am looking for every time the MusicPlayerTab is open it re runs the code from scratch instead off maintaining previous state.

1 Answer

Accepted Answer

try using the focus event or blur event

Ti.UI.currentWindow.addEventListener('focus', function(e) {
 
//code runs here???
 
});
or
Ti.UI.currentWindow.addEventListener('blur', function(e) {
 
//code runs here???
 
});

— answered 3 years ago by Arian Caraballo
answer permalink
2 Comments
  • you sir are a legend thanks for the prompt response sorted focus works for me.

    — commented 3 years ago by samuel east

  • it seems that, in my project, the focus event is fired multiple (2) times when the tab is clicked. And the blur and focus events seem to fire when screen on/ off. So it's not the same.

    — commented 1 year ago by han woolderink

Your Answer

Think you can help? Login to answer this question!