Open new window and screen Position

  • lomilmand
  • Student
  • Student
  • No Avatar
  • Joined: Jun 07, 2004
  • Posts: 91
  • Loc: Bournemouth, UK
  • Status: Offline

Post June 11th, 2004, 4:06 pm

I currently have some javascript that opens a new window (where you enter a password for a certain part of the website). This is all good and working fine, the only thing that bothers me is that the little window opens right in the top left corner, and im afraid people just won't notice it has opened.

Can someone help me wit how to get it to open at least 200 pixels in from the top and left of the screen, or ideally, right in the middle.

Here is the current script:

Code: [ Select ]
<SCRIPT LANGUAGE="javascript">
<!-- Begin
var nifty_little_window = null;
function gateKeeper() {
nifty_little_window = window.open('profilekeep.htm', 'theKeeper', 'width=300,height=120,resizable=0');
}
// End -->
</SCRIPT>
  1. <SCRIPT LANGUAGE="javascript">
  2. <!-- Begin
  3. var nifty_little_window = null;
  4. function gateKeeper() {
  5. nifty_little_window = window.open('profilekeep.htm', 'theKeeper', 'width=300,height=120,resizable=0');
  6. }
  7. // End -->
  8. </SCRIPT>


I expect that it should go in the
Code: [ Select ]
('profilekeep.htm', 'theKeeper', 'width=300,height=120,resizable=0');

part, but im no expert.

Please help. Thank you.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 11th, 2004, 4:06 pm

  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post June 11th, 2004, 7:50 pm

I think this should put it in the middle:

Code: [ Select ]
var nifty_little_window = null;
function gateKeeper() {
    var features, w = 300, h = 120;
    var top = (screen.height - h)/2, left = (screen.width - w)/2;
    if(top < 0) top = 0;
    if(left < 0) left = 0;
    features = 'top=' + top + ',left=' +left;
    features += ',height=' + h + ',width=' + w + ',resizable=no';
    nifty_little_window = window.open('profilekeep.htm', 'theKeeper', features);
}
  1. var nifty_little_window = null;
  2. function gateKeeper() {
  3.     var features, w = 300, h = 120;
  4.     var top = (screen.height - h)/2, left = (screen.width - w)/2;
  5.     if(top < 0) top = 0;
  6.     if(left < 0) left = 0;
  7.     features = 'top=' + top + ',left=' +left;
  8.     features += ',height=' + h + ',width=' + w + ',resizable=no';
  9.     nifty_little_window = window.open('profilekeep.htm', 'theKeeper', features);
  10. }


or if you want to set the top and left explicitly to 200:

Code: [ Select ]
var nifty_little_window = null;
function gateKeeper() {
nifty_little_window = window.open('profilekeep.htm', 'theKeeper', 'top=200,left=200,width=300,height=120,resizable=0');
}
  1. var nifty_little_window = null;
  2. function gateKeeper() {
  3. nifty_little_window = window.open('profilekeep.htm', 'theKeeper', 'top=200,left=200,width=300,height=120,resizable=0');
  4. }
Free Programming Resources
  • lomilmand
  • Student
  • Student
  • No Avatar
  • Joined: Jun 07, 2004
  • Posts: 91
  • Loc: Bournemouth, UK
  • Status: Offline

Post June 12th, 2004, 3:51 am

thats brilliant. thank you :)
  • lomilmand
  • Student
  • Student
  • No Avatar
  • Joined: Jun 07, 2004
  • Posts: 91
  • Loc: Bournemouth, UK
  • Status: Offline

Post June 12th, 2004, 6:10 am

i know this is really cheeky, but could the same be done for this one?

Code: [ Select ]
<script language=javascript type="text/javascript">
<!--
function ShowMeMore(picURL,picTitle,picText){
newWindow=window.open(picURL,'newWin','toolbar=no,width=500,height=333')
newWindow.document.write('<html><title>'+picTitle+'<\/title><head><\/head><body topmargin="0" leftmargin="0"><img src="'+picURL+'"alt="'+picText+'"><\/body><\/html>')
newWindow.focus()
}
//-->
</script>
  1. <script language=javascript type="text/javascript">
  2. <!--
  3. function ShowMeMore(picURL,picTitle,picText){
  4. newWindow=window.open(picURL,'newWin','toolbar=no,width=500,height=333')
  5. newWindow.document.write('<html><title>'+picTitle+'<\/title><head><\/head><body topmargin="0" leftmargin="0"><img src="'+picURL+'"alt="'+picText+'"><\/body><\/html>')
  6. newWindow.focus()
  7. }
  8. //-->
  9. </script>

where it opens in center screen again?
  • lomilmand
  • Student
  • Student
  • No Avatar
  • Joined: Jun 07, 2004
  • Posts: 91
  • Loc: Bournemouth, UK
  • Status: Offline

Post June 13th, 2004, 4:07 pm

Any clues on how to centre the window that is a result of the javascript above? Please help. You'll make my day... which will take a lot.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post June 13th, 2004, 4:44 pm

Since it worked last time I just did the same thing:

Code: [ Select ]
function ShowMeMore(picURL,picTitle,picText){
var features, w = 500, h = 333;
var top = (screen.height - h)/2, left = (screen.width - w)/2;
if(top < 0) top = 0;
if(left < 0) left = 0;
features = 'top=' + top + ',left=' +left + ',height=' + h + ',width=' + w + ',toolbar=no';
newWindow=window.open(picURL,'newWin',features)
newWindow.document.open();
newWindow.document.write('<html><title>'+picTitle+'<\/title><head><\/head><body topmargin="0" leftmargin="0"><img src="'+picURL+'"alt="'+picText+'"><\/body><\/html>')
newWindow.document.close();
newWindow.focus()
}
  1. function ShowMeMore(picURL,picTitle,picText){
  2. var features, w = 500, h = 333;
  3. var top = (screen.height - h)/2, left = (screen.width - w)/2;
  4. if(top < 0) top = 0;
  5. if(left < 0) left = 0;
  6. features = 'top=' + top + ',left=' +left + ',height=' + h + ',width=' + w + ',toolbar=no';
  7. newWindow=window.open(picURL,'newWin',features)
  8. newWindow.document.open();
  9. newWindow.document.write('<html><title>'+picTitle+'<\/title><head><\/head><body topmargin="0" leftmargin="0"><img src="'+picURL+'"alt="'+picText+'"><\/body><\/html>')
  10. newWindow.document.close();
  11. newWindow.focus()
  12. }


I added document.open and close because it acts a little weird without them in Mozilla if the javascript settings prevent you from removing the status bar. It looks like the page is still loading and hung because the document is still open for input.
Free Programming Resources
  • lomilmand
  • Student
  • Student
  • No Avatar
  • Joined: Jun 07, 2004
  • Posts: 91
  • Loc: Bournemouth, UK
  • Status: Offline

Post June 14th, 2004, 4:17 am

hooray! Genius, pure genius!
  • elektric
  • Graduate
  • Graduate
  • User avatar
  • Joined: Sep 20, 2004
  • Posts: 130
  • Loc: Mexico
  • Status: Offline

Post September 20th, 2004, 8:32 pm

Hi, I am trying to open a pop up window not exactly on an specified location (top, left), in stead, i need to make it dynamic, where I click that mouse location I want to be the value for top and left. I think this is the theory..

1. get mouse location on X
2. get mouse location on Y

myX = (X value);
myY = (y value);

--the function
window.open('somepage.html', 'somename', 'top=(myX) left=(myY) etc etc.

Any idea?
:mrgreen:

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 120 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.