PDA

View Full Version : DHTML Window centered in Browser?



Wildfire563
08-20-2006, 03:00 PM
1) Script Titles: DHTML Window and AnyLink Vertical Menu

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow.htm
http://www.dynamicdrive.com/dynamicindex1/anylinkvertical.htm

3) Describe problem:
What I'd like to do is have the DHTML window centered horizontally in the user's browser.

I found some code at www.javscripter.com to return the browser window size


<script>

//Must be placed after the Body tag is processed
//if used within a frame, it returns the size of the frame

var winW = 800, winH = 600, dWinW=594, dWinH=140;
var leftPos = 210, topPos = 140;

if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
}

leftPos = winW/2-dWinW/2+20;

document.write(
"Window width = "+winW+"<br>"
+"Window height = "+winH+"<br>"
+"DWindow LeftPos = "+leftPos+"<br>"
+"DWindow TopPos = "+topPos
)

</script>

My problems are:

1. I don't know javascript very well. I don't know how to pass the variable outside of the script into the DHTML Window script in the header. Do javascript variables live outside of a script once generated? Seems to me there could be a problem with initialization of the variables as well.

2. I am using the DHTML Window by link calls in AnyLink Vertical menu calls in the header. So how would I pass these variables here since the script must be processed in the body?

Perhaps I'm going about this all wrong?

Thanks,

Thomas

http://www.flyingscool.com/index3.htm

Click on About/About or many of the other menu choices across the top menu bar to see the window.

(Ok, another side question - why is there padding in the menu bar so the graphics don't go to the top/bottom edge of table row, even though cellpadding and cellspacing is set to 0 for the table?)