segunda-feira, 5 de janeiro de 2009
Javascript: return from an iframe
Sometimes when we use iframes (I know we all should avoid them and I most certainly do so, but when you can't really avoid them) and we need to from an inner page navigate to another page but in the main window it may not be straightforward. The problem is you never know exactly if window.parent is the root window, since it might be another iframe. In order to overcome this pitfall I implemented a simple javascript function to solve this problem:
function getRootWin(){
var win = window;
while(win.parent != null && win != win.parent){
win = win.parent;
}
return win.parent;
}
This function gets the root window so we can now do something like
win = getRootWin();
win.location.href= url;
and so go to the target page, getting rid of all the iframes the page be inside of.
Subscrever:
Enviar feedback (Atom)
Sem comentários:
Enviar um comentário