Knowing whether a javascript code is being executed inside an iframe
Sometimes it is required to know whether the code is being executed inside an iframe or not. Following code works for all browsers. var inIframe=false; try { inIframe = window.top.document == document; }catch(ex) { inIframe = true; } The reason for keeping try catch in the above logic is when ever window.top.document is accessed and if that document belongs to different domain, then IE throws Access Denied error.