FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Javascript question for those with so much knowledge they have nothing to prove :)

   
Author Topic: Javascript question for those with so much knowledge they have nothing to prove :)
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
I need to make a pop up window appear in the center of the screen. I have the window appearing how I want, but not in the correct position.

In the header of the source-of-link page:
code:
<script language="JavaScript"><!--
function P(url,h,w) { // (url,height,width)
var p = "height=" + h + ",width=" + w + ",scrollbars=yes";
window.open(url,"",p);
} // -->
</script>

The link in the body of the source-of-link page:
code:
<a href="javascript:P('smallwindow.htm',175,400)">Link to pop up window</a> 

Can I get it to appear in the center of the screen?

Disclaimer: If you take this opportunity for some macho strutting where you say I'm doing everything wrong and you could do it so much better, I'll mock you severely. Thank you.

[ June 24, 2004, 12:26 PM: Message edited by: katharina ]

Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
[Smile] Anyone?
Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
Well if you rule out macho strutting in a programming thread, do you really expect to get any responses?

[Razz] [Wink]

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Erik Slaine
Member
Member # 5583

 - posted      Profile for Erik Slaine           Edit/Delete Post 
*wanders into thread*
[Confused]
*leaves*

Posts: 1843 | Registered: Aug 2003  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
I'm hoping Zevlag will see it. [Wink] He's already the guru.

Yes, I know. I'm taking out the primary social incentive for helping someone with programming. In exchange for the help and in place of the opportunity for macho strutting, though, this answerer'll get my approval and a hug at KamaCon. And hey! Last time, Jon Boy got a dollar. All good things. [Smile]

[ June 24, 2004, 12:30 PM: Message edited by: katharina ]

Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
A hug at KamaCon? Well then forget since I probably can't make it to KamaCon. [Cry]

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
look up in your friendly Javascript (us macho programmers know it better as ECMAScript [Smile] ) reference about "window positioning", "screen positioning", or something like that.

Or you can look at a site that has a center popup, and look at the code.

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
window.moveTo(x,y)

Once you open the window, then move, that's all I know how to do, I'm not sure you can open it and locate it at the same time.

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
Hm. I've used the following concept before:

(screen.availHeight - <height>)/2

I believe the screen.availHeight and screen.availWidth properties are present across most systems. And you could probably do a simple if (screen) to verify that the OS has that property available.

You can then set the "top" attribute of window.open to the result of the function above, and set the "left" attribute of window.open to the result of screen.availWidth - <width>/2. I believe "top" and "left" are universal nowadays, but I seem to recall "screenX" and "screenY" being used for some reason in the old days.

[ June 24, 2004, 12:38 PM: Message edited by: TomDavidson ]

Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
Here we go. This was the first result for Javascript windows positioning.

You want to use the moveTo() function.

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
*cough*

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
Okay, I figured it out.

Thank you!!!! Y'all are great. [Smile] My hearty approval for the esoteric knowledge. Thanks. [Smile]

Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
Can we strut now?

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
Hey bub, I was totally posting typing it when you were posting... Plus I gave her a reference site.

[Smile]

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
Only if your ego desperately needs to, sweetie.

---

Yes, you did. Thank you so much. [Smile] Hatrack can be a source of just about all necessary knowledge. Thanks. [Smile]

[ June 24, 2004, 12:39 PM: Message edited by: katharina ]

Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
Hobbes
Member
Member # 433

 - posted      Profile for Hobbes   Email Hobbes         Edit/Delete Post 
Nah, I have so much experience writting code, and perfecting hash tbale look-ups I don't need to strut for my ego.

Hobbes [Smile]

Posts: 10602 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
You don't need to use moveTo(). As I said in my last post, you can actually specify positioning using the "top" and "left" attributes of window.open().
Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
Zevlag
Member
Member # 1405

 - posted      Profile for Zevlag           Edit/Delete Post 
I personally use the following function:
code:
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1",winProp)
else{
var winleft=(screen.width-500)/2
var winUp=(screen.height-525)/2
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left=winleft
document.getElementById("dwindow").style.top=winUp
document.getElementById("cframe").src=url
}
}

<a href="javascript:loadwindow('poopup.html',600,400)" >


Posts: 2102 | Registered: Dec 2000  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
I actually did something completely different and started from scratch, because I found a reference of how to do that.

For general information, this is what I ended up doing:
code:
<SCRIPT LANGUAGE="JavaScript">

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,
statusbar=0,menubar=0,resizable=0,width=420,
height=200,left = 326,top = 332');");
}

</script>

code:
<A HREF="javascript:popUp('smallwindow.htm')">Open the Popup Window</A>



[ June 24, 2004, 12:43 PM: Message edited by: katharina ]

Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
Zevlag
Member
Member # 1405

 - posted      Profile for Zevlag           Edit/Delete Post 
Much the same as I do. But I like mine better, gives a bit more control, and is nicer to multiple browsers. [Wink]

[ June 24, 2004, 12:47 PM: Message edited by: Zevlag ]

Posts: 2102 | Registered: Dec 2000  |  IP: Logged | Report this post to a Moderator
Bob the Lawyer
Member
Member # 3278

 - posted      Profile for Bob the Lawyer   Email Bob the Lawyer         Edit/Delete Post 
My cat's breath smells like cat food.
Posts: 3243 | Registered: Apr 2002  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
*puts head in hands* So close!
Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
Zev, why isn't that NS5 compliant? I notice you're restricting it to NS6, but I can't figure out what element there wouldn't work from NS5 on.

------

Kat, if you modify the code as I recommended, so that "top" and "left" are variables rather than static attributes, it will let you assign the window to the middle of the page regardless of the user's actual resolution. If you use your code, that window will not be perfectly centered in many browsers.

[ June 24, 2004, 12:48 PM: Message edited by: TomDavidson ]

Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
Zevlag
Member
Member # 1405

 - posted      Profile for Zevlag           Edit/Delete Post 
Tom, I honestly don't remember, I remember running into bug with something. *sigh* its been a while since I've really had to use it, I just grabbed it out of my source code snippet database (something I started keeping a few years back, has been EXTREMLY helpful) It probably could use some updating.
Posts: 2102 | Registered: Dec 2000  |  IP: Logged | Report this post to a Moderator
ludosti
Member
Member # 1772

 - posted      Profile for ludosti   Email ludosti         Edit/Delete Post 
Pop up windows make baby Jesus cry

[Wink]

Posts: 5879 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
In all fairness, I use popups for a number of things, especially data verification/alert windows for data entry screens. While they blow major chunks when used for sales, or to draw attention to pointless information, they make nice dialog boxes.

[ June 24, 2004, 12:55 PM: Message edited by: TomDavidson ]

Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
ludosti
Member
Member # 1772

 - posted      Profile for ludosti   Email ludosti         Edit/Delete Post 
Yeah, pop-ups have their legitimate uses. It's just their over and misuse that have given them a bad rap.

[ June 24, 2004, 01:01 PM: Message edited by: ludosti ]

Posts: 5879 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
advice for robots
Member
Member # 2544

 - posted      Profile for advice for robots           Edit/Delete Post 
ludosti: [Big Grin]

BtL: [Big Grin]

Humor after my own heart.

Posts: 5957 | Registered: Oct 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
A technique I quite like for many uses is in-page popups. In other words, divs in the page at a closer z level, controlled using the DOM, usually.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
katharina
Member
Member # 827

 - posted      Profile for katharina   Email katharina         Edit/Delete Post 
Update for anyone who cared: The request for this page was fourth-hand by the time it got to me, and the original need was for something completely different. *sigh* I need a Dr. Pepper.
Posts: 26077 | Registered: Mar 2000  |  IP: Logged | Report this post to a Moderator
Zevlag
Member
Member # 1405

 - posted      Profile for Zevlag           Edit/Delete Post 
Hmm, me too, and the fridge here at work is empty...
Posts: 2102 | Registered: Dec 2000  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2