I am trying to open a new window and close its parent window, so that I can't return to previous window and keep the application more efficient.
However calling close on parent window causes the new window to be closed as well, regardless if I call it before opening the new window or after.
What happens is new window is being opened and then closed right away.
I tried to open a new window on the event listener close for parent window... but that doesn't help.
Code example:
`app.js:`
var loginWin = Ti.UI.createWindow({
url:login.js
});
loginWin.open();
`login.js:`
var win = Ti.UI.currentWindow;
var btn = Ti.UI.createButton({.....});
btn.addEventListener('click',function(e){
//putting win.close() also causes the problem
var appCoreWindow = Ti.UI.createWindow({
url:"core.js"
});
win.close();
appCoreWidnow.open();
});
win.add(btn);
You are creating Window object inside eventhandler and when function finishes garbage collector removes all local variables from it, including appCoreWindow.
Try this instead:
var win = Ti.UI.currentWindow;
var appCoreWindow = Ti.UI.createWindow({ url:"core.js" });
var btn = Ti.UI.createButton({.....});
btn.addEventListener('click',function(e){
appCoreWidnow.open();
win.close();
});
win.add(btn);
Related
I have a Electron App which, on the press of a button, opens a new Window. Said Window has another button with the id of "closeBtn". Now i try to handle it in the js associated to said element with the following code
const electron = require("electron")
const path = require("path")
const remote = electron.remote
const closeBtn = document.getElementById("closeBtn")
closeBtn.addEventListener("click", function(e) {
var window = remote.getCurrentWindow();
window.close();
})
But somehow that doesn´t work, and the new window is not closing on the Button Press. What am i doing wrong?
Fixed it by adding webPreferences {nodeIntegration: true} to the values of my newly generated Window.
I use a toolbar button to toggle between normal and private windows.
Here is the code:
OpenBrowserWindow({private: !PrivateBrowsingUtils.isWindowPrivate(window)});
setTimeout(BrowserTryToCloseWindow, 80);
I use 'setTimeout' in order to prevent some flickering.
When the new window opens, it gets the focus.
When the command 'BrowserTryToCloseWindow' is executed, the focus returns to the old window.
When the old window is closed, the new one does have the focus, but it isn't 'checked / active' in Windows Task Bar.
I suppose I need to use ITaskbarList::ActivateTab in order to activate the new window in the task bar.
I have the (very) basic direction:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("shell32.dll");
var taskBar = lib.declare(---
taskBar---
lib.close();
I'd appreciate your help.
Win 7, 32-bit, Classic Theme.
Posted here too.
Solution:
function togglePB(click)
{
var newWin = OpenBrowserWindow({ private: ! PrivateBrowsingUtils.isWindowPrivate(window) });
if(click.button == 0)
newWin.addEventListener("focus", function switchWindows() { window.focus(); BrowserTryToCloseWindow(); newWin.removeEventListener("focus", switchWindows); });
}
http://forums.mozillazine.org/viewtopic.php?f=19&t=2895755
Is there something in firefox addon through which we can register a callback which gets invoked when the addon is closed by clicking the x button on the left?
What I need is, when a user closes the addon bar using the x button, my extension loaded on that bar should be notified. Now what happens is, even though the user closes the addon bar, it is not getting closed; instead it just hides.
If we can be informed through a callback that the user has clicked on x button, then i could listen to that in the extension.
Yes sir there absolutely is: MutationObserver.
Copy paste this to a scratchpad file in Browser envirnoment and then as addon bar is closed and opened you will see a message.
// select the target node
var win = Services.wm.getMostRecentWindow('navigator:browser');
var target = win.document.querySelector('#addon-bar');
// create an observer instance
var observer = new win.MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName == 'collapsed') {
Services.prompt.alert(null,'title','addon bar toggled it WAS = ' + mutation.oldValue);
}
});
});
// configuration of the observer:
var config = { attributes:true, attributeOldValue:true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
//observer.disconnect();
The easiest way to do this is to attach a command handler to the button in question. If your code runs inside the browser window, this will do:
var closeButton = document.getElementById("addonbar-closebutton");
closeButton.addEventListener("command", function(event) {
// Add-on bar is being closed, do something
}, false);
Note that this code is bound to stop working very soon as the add-on bar is being removed from Firefox.
I have a surely somehow stupid problem with adding an eventlistener to a window I create in a commonJS module in Titanium Mobile.
Consider i.e. the following code:
var SegmentListWindow = function(){
var window = S.ui.createWindow("Testwindow");
window.addEventListener("app:customListener", function(){ doSomething();});
return window;
}
exports.SegmentListWindow = SegmentListWindow;
The window is nicely generated using
var Window = require(".....").SegmentListWindow;
var win = new Window();
S.ui is just a simple helper method to create some standard window in my app.
But the event listener is never called, I tryTi.App.fireEvent("app:customListener"), but the event doesn't reach the listener.
Only when Using Ti.App.addEventListener and adding a global eventlistener it's working.
I think maybe that problem is I am not adding the event listener to the "instance" of the window? But how to fix this? I don't want to add the event listener manually when instantiating the window somewhere in the app. Can't I do this in the commonJS module?
Well, that really was a simple question.
I am doing a Ti.App.fireEvent, but was listening for window.addEventListener, that couldn't work.
Now I am doing the following:
Adding an eventlistener on window instantiation to the global Ti.App-Object, and remove this listener on the window's close event.
That works perfectly.
You could also define the SegmentListWindow as you did in the question:
var SegmentListWindow = function(){
var window = Ti.UI.createWindow({title:"Testwindow"});
window.addEventListener("win:customListener", function(){ doSomething();});
return window;
}
exports.SegmentListWindow = SegmentListWindow;
and then fire the event on the win object:
var Window = require(".....").SegmentListWindow;
var win = new Window();
win.fireEvent('win:customListener');
I am developing an iOS app in Appcelerator and I want to switch between windows with the use of a swipe event listener. How can I do this? The below code does not work. The current window that I "start" from contains a table.
var window = Ti.UI.currentWindow;
window.addEventListener('swipe', function() {
// Create the new window
var win = Titanium.UI.createWindow({
title: 'Contacts',
url:'contacts_simple.js'
});
// Animate the page turn
Titanium.UI.currentTab.open(win, {animated:false});
});
I think the problem is with the Ti.UI.currentWindow. Depending on the context you're working in it may not be valid.
Google 'appcelerator currentWindow', but here's a related link:
http://developer.appcelerator.com/question/5391/currentwindow
This will not be optimal and dynamic, but to start with, try referencing the window implicitly. Meaning if you did something like
var window_x = Ti.UI.createWindow({});
try
window_x.addEventListener('swipe', function() {...});