views:

420

answers:

1

For FF and other non-IE browsers, window.opener.outerWidth/Height give me the info I need. For IE, I'm still at a loss, from IE6 to 8. I can't use jquery as the opener's page is beyond my control, so I can't do a window.opener.$(window). This requires the opener to have jquery 'attached' (correct me if I'm wrong).

I googled quite a bit and also searched this site, still can't find a definite neat answer.

To add: I really need the outer size so that I can do a resizeTo(w, h) for the opened window where w and h are calculated based on a ratio of the opener's size. "resizeTo" ironically sets the outer size for IE and other browsers. I also tried a messy loads of stuff using resizeBy, not good enough.

+3  A: 

outerWidth and outerHeight define dimensions of the browser window (including sidebar, window chrome and window [re-]sizing borders/handles). Unfortunately you cannot get these dimensions in IE - only the window viewport dimensions are available (good enough for most applications I've seen). Aka window.innerWidth/window.innerHeight.

jQuery can give you the dimensions of the current window viewport, but not other windows (eg, openers, children, etc). So you'll have to code this yourself. Here is a crude sample:

// get viewport size (without scrolling) of the given window object
function clientSize(win) {
 var width, height;

 if(win.innerWidth || win.innerHeight) {
  width = win.innerWidth;
  height = win.innerHeight;
 } else {
  var doc = win.document;
  width = doc.documentElement.clientWidth || doc.body.clientWidth;
  height = doc.documentElement.clientHeight || doc.body.clientHeight;
 }

 return { width:width, height:height }
}

Try it like:

var openerSize = clientSize(window.opener); 
// now use openerSize.width, openerSize.height

Also note that you can't read any of these values if the given window has loaded a document from another domain (security measure).

Crescent Fresh
@crescentfresh Thanks for the answer. I've actually tried using the method you mentioned before I posted this question. The issue is, I really need the outer size so that I can do a resizeTo(w, h) for the opened window where w and h are calculated based on a ratio or the opener's size. "resizeTo" ironically sets the outer size for IE and other browsers. I also tried a messy loads of stuff using resizeBy, not good enough. Anyway +1 for your inputs :)
o.k.w
@o.k.w: if your end goal is to call `resizeTo()`, you can do the trick here: http://www.faqts.com/knowledge_base/view.phtml/aid/1178 All it does is issue a throwaway fixed sized call to `resizeTo(500, 500)`, subtract the values IE reports, and use those in the *real* `resizeTo` call later.
Crescent Fresh
@crescentfresh My end goal is to have the new window resized to a fixed ratio of the opener. So resizeTo is the most straightforward. ResizeBy was a side trip I tried. Your suggestion will work though kinda unorthodox, yeah? Anyway, appreciate it and if no better solution comes along, I might just do that. :-)
o.k.w
@o.k.w: yeah it's very unorthodox. The reason it may be an acceptable solution is because you're going to be doing a `resizeTo()` *anyway*. Otherwise, you'd be sizing the window for no apparent usefulness to the user experience.
Crescent Fresh