You can get reference to window by index method. Below code will help find the index of web page opened:
String pageindex = web.getFocusedWindow().getAttribute("index");
Here variable pageindex will contain value 0 or 1 or 2.. depending on number of webpages opened.
You can replace index value in the web.link code.
Indexing will always starts from "0" for first opened web page and so on.
Thanks and Regards,
Vasanth Kumar S M