He suggested cookies, which was the obvious choice, but I needed a way to differentiate between windows. The problem is that when the window reloads it loses its state and I was searching for an anchor on each window. Of course there are other options which you might use like saving the last tab on the opener window or save it on the server but that didn’t seem right. The opener can be closed at any time and saving it on the server is an over kill and requires me to handle pages per user.
I did some digging and found that after the page is saved (crmForm.FormType=2) the window name is retained between saves and so I can use that as the basis for a cookie name and extract it when the page loads. I tested it on IE7 and it seems to work smoothly. The cookie expires when the navigator session is closed.
Paste the code inside each entity onload event.
If you’re having any issues let me know (Comment).
// JScript File
if( crmForm.FormType == 2)
crmForm.attachEvent( "onsave" , OnCrmPageSave );
var regTab = new RegExp( window.name + "=(\\d)","gi");
var tab = document.getElementById("tab"+RegExp.$1+"Tab");
if( tab ) tab.click();
var crmTabBar = document.all.crmTabBar;
for(var i = 0 ; i < crmTabBar.childNodes.length ; i++)
if( crmTabBar.childNodes[i].className.indexOf("ms-crm-Tab ms-crm-Tab-Selected") != -1 )
document.cookie = window.name+"="+i;