Skip to content

Instantly share code, notes, and snippets.

@dennishall
Last active December 17, 2015 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennishall/5568749 to your computer and use it in GitHub Desktop.
Save dennishall/5568749 to your computer and use it in GitHub Desktop.
Give identifying classnames -- css / styling hooks -- to pages opened by window.open and pages that are iframed.
var _open = window.open;
window.open = function(a,b,c,d,e,f){
var popupHandle = _open(a,b,c,d,e,f);
try {
popupHandle.isPopup = true;
}catch(e){
//for pdf pop-ups
}
return popupHandle;
};
var w = window, ua = navigator.userAgent, s='js', k, v;
var o = {
ie : /MSIE/.test(ua) && (document.documentMode || ua.replace(/.*?MSIE (.).*/,"$1")),
ff : /Firefox/.test(ua) && ua.replace(/.*?Firefox\/(.)\.(.).*/,"$1_$2"),
safari : /Safari/.test(ua) && ua.replace(/.*?Version\/(.).*/,"$1"),
chrome : /Chrome/.test(ua) && ua.replace(/.*?Chrome\/(.).*/,"$1"),
opera : /Opera/.test(ua) && ua.replace(/.*?Opera\/(.).*/,"$1")
};
//if(w.opener && w != w.opener) o['poppedUp'] = ' ';
for(k in o) if(o.hasOwnProperty(k)){v=o[k]; s += ' ' + (v ? k + " " + k + v : '');}
if(w.isPopup) s += ' poppedUp';
s += /Windows/.test(ua) ? " pc" : " mac";
//are we in compatability mode?
if(document.documentMode && (document.documentMode != 1 * ua.replace(/.*?MSIE (.).*/,"$1"))){
s += ' compatibilityMode';
}
if(w != w.top){
var isIframe = true;
// or is it a frame in a frameset? (!)
var frames = top.document.getElementsByTagName('frame');
for(var i=0,l=frames.length;i<l;i++){
if(window == frames[i].contentWindow){
isIframe = false;
}
}
s += (isIframe ? ' i' : ' ') + 'framed';
}
document.getElementsByTagName("html")[0].className = s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment