2

I am using a track window which opens with an onclick button, but when the button is clicked the second time, I wish to focus the window without refreshing the content. The code below works well to focus the window but it refreshes the content. Can anyone suggest how to focus the window without refreshing the content ?

<script>
function trackOpenWindow()
{
memwin=window.open("TRACK_Member.php", "myWin2", "toolbar=yes, scrollbars=yes, resizable=yes, height=590,width=1200");
if(window.focus)
memwin.focus()
if(!memwin.close)
memwin.focus()
}
</script>
<button name="subject" id="button1" type=" submit" style= "height:250px; width:480px; float:right" onClick='trackOpenWindow();'><h1>TRACK ACTIVITY</h1></button>

1 Answers1

4

Before you create the window first check if it already exist and is not closed, when it's still there and open only set the focus:

if (!window.memwin || window.memwin.closed) {
    window.memwin = window.open("TRACK_Member.php", "myWin2", "toolbar=yes, scrollbars=yes, resizable=yes, height=590,width=1200");
}
window.memwin.focus();

Demo: http://jsfiddle.net/2e627tco/4/

Note: it depends on individual browser-settings if it's possible to set the focus to other windows.

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201