Skip to content Skip to sidebar Skip to footer

Is There A Cross-browser Method To Bring A Popup Window Into The Foreground?

I have a chat in a popup browser window. This chat page (ASP) checks for new messages every 10 seconds. I would like to bring this popup window to front when there is a new messa

Solution 1:

Don't steal the focus.

And no, it will work only in some IEs, as you said. Quoting Mozilla's developer network,

It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.

This is valid for all modern browsers, I guess.

You can use the following approach in order to notify the user of an activity.

Solution 2:

Yes, there is a way out. You can use the JavascriptExecutor class to get the hidden browser and switch to it. This will bring the browser to the foreground.

Stringwindow = driver.getWindowHandle();
((JavascriptExecutor) driver).executeScript("alert('Test')");
 driver.switchTo().alert().accept();
 driver.switchTo().window(window);

Post a Comment for "Is There A Cross-browser Method To Bring A Popup Window Into The Foreground?"