Window Opening with Focus

A new window can be opened with a new HTML document using the onClick attribute of the anchor tag. However if the window your user is 'trying' to pop-up is already open, but behind other windows your user will be come confused and click a bunch of times and not see the window. The window is already there it needs to be brought to the front. So, we need to add a bit of JavaScript to force the window to the front - we need to gain FOCUS.

Sample code for the link below:

<a HREF="something.html" TARGET="somewindow" onClick="newwin=window.open('something.html', 'somewindow', 'width=300, height=200 toolbar=no, status=yes'); if (window.focus) {newwin.focus()};">Something</a>

Important note: you must name the window when you create it, such as newwin, by doing the assignment newwin=window.open(...). Later in the code we can test to see if the current window has focus (if (window.focus)) and if it does, change the focus (newwin.focus()). There is nothing special about the variable newwin, you can use any valid variable name.

Link:

Something

Try clicking on the link, then place it behind other windows but do not close it. Then bring this window back to the front and click on the link again. The window with something.html should come forward and be on top of all the other windows.