Click to See Complete Forum and Search --> : Open a screen centered, sized window
shotsy247
01-06-2004, 10:16 AM
Forgive a newb.
I am trying to open a new window, with a set size, centered on the screen.
Here is what I have so far. This script is all within the body.
<script type="text/javascript">
function openwin(args) {
var w =640;
var h = 480;
var l = (screen.width - w) / 2 ;
var t = (screen.height - h) / 2;
window.open(args, "thisWin","width=640, height = 480", "top = t, left = l","scrollbars=0, toolbar=0, menubar=0, resizable=0, location=0, status=0");
}
</script>
<a href="#" onClick="javascript:openwin('http://www.somepage.html'); return false;">Module 1: Color & Design Features of Area Rugs</a>
Thanks for the help.
_t
olerag
01-06-2004, 12:52 PM
Your almost there...how about...
<script type="text/javascript">
var newWin;
function openWin(val) {
var w = 640;
var h = 480;
var l = (screen.width - w) / 2 ;
var t = (screen.height - h) / 2;
var winAtt = "width="+w+",height="+h+",top="+t+",left="+l+",scrollbars=0,toolbar=0,menubar=0,resizable=0,location=0,status=0";
newWin = window.open(val, "newWin", winAtt);
}
</script>
shotsy247
01-06-2004, 01:54 PM
No go. I cut and paste your code over mine and it still didn;t work.
Can the function be located in the body of the page or does it have to go in the head?
Why do you place all of the attributes into a var? Does this make a difference?
_t
Pittimann
01-06-2004, 02:07 PM
Hi!
I guess, you just pasted olerag's script an didn't alter the rest. The link you open the window with, calls a function named "openwin", the name of olerag's function is "openWin".
Don't forget, that js is case sensitive...
Cheers - Pit
olerag
01-06-2004, 02:19 PM
Arggh. sorry. Shoulda just left it out.
shotsy247
01-06-2004, 02:21 PM
Thanks for all of your help olerag and Pittimann, but this isn't working. I think it may have something to do with my host, I have a call into them.
What I have been able to got working is this code:
<a href="#" onClick="window.open('http://www.somePage.html','newWin', 'height=500, width=640, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')">Module 1: Color & Design Features of Area Rugs</a>
As you can see this sizes the window, but doesn't center it. Is there any way to center the window, without calling a function?
_t
olerag
01-06-2004, 02:25 PM
Well, in your last example your not specifying the left or
top positions. Don't know what to say cuz it centers in the
screen for me with all browsers.
And you can add the "screen" height,width built-ins if you
prefer to call it from your anchor instead of making a
function (which, I believe, you had in your first thread).
If this is gonna be a pop-up though, I suggest you make
it a function and include the reference to the new window
as a global. Chances are your eventually going to need a
little communication between the two windows.
Paul Jr
01-06-2004, 05:26 PM
http://www.webdevfaqs.com/javascript.php#centeredpopup