Reputation: 50832
If a user clicks on a button a new window opens where the user can do irrelevant stuff. In case the user clicks on the former page the new window gets pushed into the background and the user is not able to see it anymore. That is notmal behaviour so far.
What i need now is that the already opened window comes back to the front on a second button click of the user. Is this possible? How?
Upvotes: 0
Views: 185
Reputation: 586
Check to see if the window exists. If not, create it. If it does the give it the focus. Something like the following should do the trick.
<html>
<head>
<script language="JavaScript">
var popup;
function getWindow() {
if(popup==null) {
popup=window.open("http://www.stackoverflow.com");
}
else {
popup.focus();
}
}
</script>
</head>
<body>
<input type="button" value="Click me..." onClick="getWindow()" />
</body>
</html>
Upvotes: 1