If a window is not opened with window.open()
, you won't be able to resize it.
It's also impossible to tell if the window has been minimized or if the user has switched to a different tab.
There are two possible solutions:
- First, open the current window using
window.open()
.
or
- Second option is to open a new window when the current one is minimized.
Here is the code for the second approach:
var url = "http://google.com";
var options = "resizable"+
",height=500,width=500"+
",top=9999,left=0"; // positioned at bottom left
// Check for browser visibility change
document.addEventListener("visibilitychange", function() {
if(document.hidden){
// Open new window when current one is minimized or tab is switched
window.open(url, "window name", options);
}
else{
// Handle window restoration
}
}, false);