Page 1 of 1
JavaScript : Centering a Pop-up window
Posted: Mon Apr 21, 2003 10:42 am
by glenn
Hello,
Thanks for the help on the Random Image function, Rob the R, it worked for me

.
I have been looking around on the net and in my books but I have not found anyting let but iam sure I have seen a function some where. I am looking for a function that will position my pop-up in the center of the page, e.g 50% from the top and 50% from the side.
Heres what I have so far ::
function open_b_s7() {
leftPos = 0
height = 0
if (screen) {
leftPos = screen.width-225
height = screen.width-0
}
window.open("episodes/b_s7.html", "test", "left="+leftPos+", top="+height+", width=200, height=320, toolbar=no, status=no, resizeable=no, menubar=no, scrollbars=no")
}
If any one can help me with this I would be thank fall.
Glenn Curtis.
Posted: Mon Apr 21, 2003 12:50 pm
by phpfreak
Posted: Wed Apr 23, 2003 10:52 am
by dstefani
Here is something I've used without any problems.
Have fun.
- Don
Code: Select all
// In head
<script language="JavaScript">
<!--
function openWindow(theURL,winName,features, myWidth, myHeight, isCenter) {
if(window.screen)if(isCenter)if(isCenter=="true"){
var myLeft = (screen.width-myWidth)/2;
var myTop = (screen.height-myHeight)/2;
features+=(features!='')?',':'';
features+=',left='+myLeft+',top='+myTop;
}
window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
//-->
</script>
// In body
// This example uses a image link
<a href="javascript:;" onClick="openWindow('popup_page.html','','toolbar=no,status=no','750','450','true')">
<img src="images/openMe.jpg" width="253" height="144" border="0" alt="Click to open popup!"></a>
Posted: Wed Apr 23, 2003 3:40 pm
by glenn
Thanks for the function but I have told my self that I shouldn't use JavaScript that I don't understand!!
Could anyone explain the above function
Please explain it in a simplest way has you can. I am having a lot of problems with getting my head around JavaScript! I can understand other languages like PHP but JavaScript is just a little different, I think my problem is that no other languages I have seen have dots ( . ) used to space commands!!
Don't take this the wrong way, its just that if iam ever to build websites for a big company (which I hope I will someday) I would think they would need me to understand how JavaScript works!!
Like I say thanks for the function anyway!!
Glenn Curtis
Posted: Wed Apr 23, 2003 5:20 pm
by dstefani
Perfect opportuity to get the Oreilly JavaScript book and figure out how it works. No sarcasim intended.
- Don
Posted: Wed Apr 23, 2003 7:45 pm
by glenn
Whats the ponit??
I have about 4 books on JavaScript and I have read and re-read them again and again and again and again. Plus the fact that I dont like Oriley's books as I think that they dont give a lot of code examples and thats how I tend to learn things (like PHP!).
But it doesn't matter, I may give it another go my-self and when that doesn't work I will just give it a fixed position!
But thanks all the same!!!!

Posted: Thu Apr 24, 2003 3:11 am
by twigletmac
glenn wrote:Plus the fact that I dont like Oriley's books as I think that they dont give a lot of code examples and thats how I tend to learn things (like PHP!).
They're an excellent reference though - very handy when you do have examples to decipher (like dstefani gave above). However, you could find another reference (probably free) on the web to work out what it's doing... no need to dismiss the example out of hand.
Mac
Posted: Thu Apr 24, 2003 3:39 am
by patrikG
Oh, and I think O'Reilly publishes great books!
