Handling popup windows
From Chickenfoot Script Repository
// ==UserScript==
// @name Handling popup windows
// @when Pages Match
// @description changes chickenfoot focus to popup window
// @include *
// ==/UserScript==
//When a web page creates a popup window, a Chickenfoot script running in the //original window doesn't automatically switch focus to it. For example, this //script doesn't work:
// go("www.citizensbank.com")
// click("View Demo") // pops up a window with the demo in it
// click("NEXT") // doesn't work, because the NEXT button is in the popup //window
//Here's a temporary workaround, which may be a little unreliable but should work //for a lot of popups. This function will find the popup window that's on top and //return it. (Note: this function refers to an internal interface, //Chickenfoot.Tab, which may change in future
//releases.)
function popupWindow() {
sleep(0.1) // give the popup window time to appear
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var popupChromeWindow = wm.getMostRecentWindow(null);
var popupHTMLWindow = popupChromeWindow.content;
return new Chickenfoot.Tab(popupHTMLWindow);
}
//To use this function in a script, call it using with(). Here's the fixed //version of the script above.
go("www.citizensbank.com")
click("View Demo") // pops up a window with the demo in it
with (popupWindow()) {
// now operating on the popup
click("NEXT")
}
As an alternative that is not so elegant, you can also force Firefox to open popups in a new tab. Type in the address bar
about:config
and make the following changes:
browser.link.open_external -> 3 browser.link.open_newwindow -> 3 browser.link.open_newwindow.restriction -> 0
