var ___rootFound; function _doSearchForRootWindow () { var curWin = window; if ((curWin != curWin.parent) && ! curWin.rootMarker){ // Check for the presence of an arbitrary value that should only exist on the webapp root if (curWin.parent.rootMarker) { curWin = curWin.parent; } else { // Otherwise call recursively. // Well, not really recursively because the scope is different, // but I don't have a better word for it. curWin = curWin.parent.getWebappRoot(); } } while (curWin.opener && ! curWin.rootMarker) { curWin = curWin.opener.getWebappRoot(); } return curWin; } function getWebappRoot () { if (! ___rootFound) ___rootFound = _doSearchForRootWindow (); return ___rootFound; } function _root(){ return getWebappRoot(); }