Window Refocus

this script allows you to refocus a window that you created via javascript

by zachary cross

HTML

<!DOCTYPE html>
<html>
<body>
<p>Click the button to open a new window, and assure that the new window GETS focus (send the new window to the front).</p>
<button onclick="myFunction()">Try it</button>
<button onclick="Refocus()">Refocus Window</button>
<!--<button onclick="start()">stay on top</button>-->
</body>
</html>

JavaScript

//creates the window
function myFunction() {
	var myWindow = window.open("", "myWindow", "width=200,height=100");
  myWindow.document.write("<p>A new window!</p>");
  myWindow.focus();
}
//this refocuses the script
function Refocus() {
window.open('', 'myWindow').focus();
}

/*function start() {
    setTimeout(Refocus, 3000);
}*/