Page 1 of 1

[Javascript] Open window under button by clicking it

Posted: Sun Aug 07, 2005 8:17 am
by tores
Hi

I call the following function to open a window beneath a button.

Code: Select all

/* Opens a window just beneath the element given as trigger */
function windowopen_relative(trigger, url, window_name, height, width) {
	var browser_left_offset = window.screenX;
	var browser_top_offset = window.screenY;
	var browser_left_frame_width = (window.outerWidth-window.innerWidth)/2;
	var browser_top_frame_height = 150; // Is correct only as long as all toolbars are displayed
	var	leftpos = trigger.offsetLeft + browser_left_offset + browser_left_frame_width;
	var	toppos = trigger.offsetTop + trigger.offsetHeight + browser_top_offset + browser_top_frame_height;
	
	var parent = trigger;
	do {
		parent = parent.offsetParent;
		leftpos += parent.offsetLeft;
		toppos += parent.offsetTop;
	} while(parent.tagName!="BODY");

	window.open(url, window_name,
	"height="+height+",width="+width+",top="+toppos+"px,left="+leftpos+
	"px,srollbars=yes,menubar=no,titlebar=no,toolbar=no,directories=no,location=no,status=no");
}
As you can see the browser_top_frame_height is statically set to 150px... This displays nicely as long as all toolbars (Navigation and Bookmarks toolbar in firefox) are displayed. Does anyone know how this variable may be given the correct value in all cases.