frequently ask ? : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 11 people (73%) answered Yes
Recently 6 of 7 people (86%) answered Yes

Entry

How do I open a couple of windows and allow navigating forth and back between them?

Mar 24th, 2001 04:31
Martin Honnen,


In the main window that opens the other windows keep an array of opened 
windows. Then have navigational links which refer back to the opener 
window's windows array.
<HTML>
<HEAD>
<TITLE>
window 0
</TITLE>
<SCRIPT>
var windows = new Array();
windows[0] = window;
function makeWindow () {
  var i = windows.length;
  var win = windows[i] = open('', 'window' + i);
  var html = '';
  html += '<HTML>';
  html += '<HEAD><TITLE>Window ' + i + '<\/TITLE><\/HEAD>';
  html += '<BODY>';
  html += '<A HREF="javascript: void 0"';
  html += '   ONCLICK="var win = opener.windows[' + (i - 1) + '];';
  html += '            if (win && !win.closed)';
  html += '              win.focus();';
  html += '            return false;';
  html += '           "';
  html += '>previous window<\/A>';
  html += ' | ';
  html += '<A HREF="javascript: void 0"';
  html += '   ONCLICK="var win = opener.windows[' + (i + 1) + '];';
  html += '            if (win && !win.closed)';
  html += '              win.focus();';
  html += '            return false;';
  html += '           "';
  html += '>next window<\/A>';
  html += '<\/BODY>';
  html += '<\/HTML>';
  with (win.document) {
    open();
    write(html);
    close();
  }
}
for (var w = 0; w < 5; w++)
  makeWindow();
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript: void 0"
   ONCLICK="if (windows[1]) windows[1].focus(); return false;"
>
next window
</A>
</BODY>
</HTML>