It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming HTML Forum

x/y position of last popup

x/y position of last popup

Postby siege on Mon Apr 23, 2007 7:27 am

Can you store the last known position of a popup to be used for the next window the user pops up form the parent? This is driving me nuts trying to get an answer on this. Ex: user clicks on a link in the parent, a window pop up, the user moves it to a different location on the screen, then requests a new popup from the parent, this new pop up is now opened in to that location :?:
Last edited by siege on Mon Apr 23, 2007 4:56 pm, edited 1 time in total.
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am

Postby LucasZ21 on Mon Apr 23, 2007 4:08 pm

You can probabally do it...but it's not HTML.
Image
User avatar
LucasZ21
100+ Club
 
Posts: 195
Joined: Mon Feb 26, 2007 3:31 am
Location: Mansfield, OH

Postby siege on Mon Apr 23, 2007 4:57 pm

thanks. do you have any idea of what language I could use. i thought maybe JS but no one seems to be biting there?
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am

Postby LucasZ21 on Mon Apr 23, 2007 5:59 pm

I dont really have any idea lol I just know it's not HTML
Image
User avatar
LucasZ21
100+ Club
 
Posts: 195
Joined: Mon Feb 26, 2007 3:31 am
Location: Mansfield, OH

Postby siege on Mon Apr 23, 2007 6:19 pm

ha ha.. i got ya.... well maybe someone else will know... have a good day
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am

Postby mwa103 on Mon Apr 23, 2007 6:55 pm

Are you wanting to open a second popup window in the same location, or do you just want the link to open in the same window and not have the window move. If it is the latter of the two, that may be a bit easier to implement using JavaScript. Not sure how you would do it yet, but I'll do some research for you.

-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 11:55 pm

Postby mwa103 on Mon Apr 23, 2007 7:08 pm

Looks like it's not as hard to do it the first way after all. I found this page which shows script for opening a new window at the same location as a window that is open. Not sure what you would do about one that the user closed.

-Mike

http://www.faqts.com/knowledge_base/view.phtml/aid/2310/fid/124
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 11:55 pm

Postby siege on Mon Apr 23, 2007 7:41 pm

I want the new popup to open in the same location that the last popup has been dragged to..... in some instances the user might have left it centered, but for most they drag it to a different location besides the default center. Now BNasically each successive popup 'pops up' in the user's desired location. If they close it (whether its the first or next couple) the variables x and y are stored. Again, I got the thing to center on first popup, but i cant figure out how to establish the above. Thanks for your help.
I do want each link to open in whther its the same or one of the same name that reloads the info is fine. I will be using the same 'windowName' for each link.
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am

Postby mwa103 on Mon Apr 23, 2007 8:32 pm

The ideal way to do this would be to use the onMove function, but I couldn't get it to work. I was able to put something together that should work though. I used the onLoad & onUnload functions to call a method which reports back to the opening window the popup's current location. I couldn't find any way to detect when the window was moved, so I had to use the setTimeout method to check every 5 seconds to see if the window had moved. Also, when the popup is closed, the onUnload function calls the same method to update the x & y. Not sure if this is 100% what you want, but it's as close as I could get. Good luck.

-Mike

Opening window:
Code: Select all
<html>
<head>
<title>Popups</title>
<script type="text/javascript">
   var x=300;
   var y=200;
   var numWindows = 0;
   function updateXY(newx,newy)
   {
      x = newx;
      y = newy;
      alert(x + " x " + newy);
   }
   function openPopup(address)
   {
      open(address, 'testing'+numWindows, 'left=' + x + ',top=' + y + ',resizable=0,scrollbars=1,width=400,height=400');
      numWindows++;
   }
</script>
</head>
<body>
   <input type=button name=testButton onClick="openPopup('test.html')" />
</body>
</html>


test.html (the popup)
Code: Select all
<html>
<head>
<title>Testing</title>
<script type="text/javascript">
   var myX=0;
   var myY=0;
   function updatePos()
   {
      if (document.all) {
         var x = window.screenLeft;
         var y = window.screenTop;
      }
      else {
         var x = window.screenX;
         var y = window.screenY;
      }
      if(x!=myX || y!=myY)
      {
         window.opener.updateXY(x,y);
         myX=x;
         myY=y;
      }
      setTimeout("updatePos()", 5000);
   }
</script>
<body onLoad="updatePos()" onUnload="updatePos()">
   <h3>This is a test</h3>
</body>
</html>
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 11:55 pm

so close

Postby siege on Tue Apr 24, 2007 12:02 am

thank you so much so far for your help.... its close... the very first pop has to be centered, then the rest use your x/y functions.... heres what im using in replacement of your openPopup function, tell me, is there a way to turn my centering function off after it has been used the first time?
Code: Select all
[size=18]var win=null;
function popMe(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+y+',left='+x+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}[/size]
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am

Postby mwa103 on Tue Apr 24, 2007 1:41 am

You could try setting a flag variable to signify whether or not you have opened one already. Something like:

Code: Select all
var win=null;
var openedYet=false;
function popMe(mypage,myname,w,h,scroll,pos){
if(!openedYet){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
openedYet=true;
}
else{
    x=newX;
    y=newY;
}
settings='width='+w+',height='+h+',top='+y+',left='+x+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';

win=window.open(mypage,myname,settings);}

Where newX & newY would be the x & y from my previous post.
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 11:55 pm

Postby siege on Wed Apr 25, 2007 1:34 am

This seemed to work, just right. Thanks for your help. :D
I would like to use my variable 'myname' to set the popup to focus()... in my example I am setting the wrong window (the parent) to be on top. In flash I would do this like _root[myname].focus(); whats the equivilant in JS? I am using XHTML and I cannot put onBlur in the body tag of the test.html b/c it seems that is not allowed.

Code: Select all
var win=null;
var openedYet=false;
function popMe(mypage,myname,w,h,scroll,pos){
   alert ("area 0");
   if(!openedYet){
    alert ("area 1");
      if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
      if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
      else if((pos!="center" && pos!="random") || pos==null){
         LeftPosition=50;
         TopPosition=50;
          alert ("area 2: Did not specify correct position  or gave no position");
      }
      openedYet=true;
      }else{
       LeftPosition=x;
       TopPosition=y;
        alert ("area 3: feeding local var the root var");
   }
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
alert ("area 4");
win=window.open(mypage,myname,settings);
myname.focus();
}
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am

Postby mwa103 on Wed Apr 25, 2007 4:43 pm

Not completely sure, but I think you want to use the win variable instead of the name. The win variable references the popup window so you should be able to put it:
Code: Select all
win.focus()


Here is a link to a page on quirksmode.org that talks about focus & popup controls. Good luck.

-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 11:55 pm

Postby siege on Wed Apr 25, 2007 4:48 pm

thanks for all your help. See you around.
best
siege
siege
 
Posts: 31
Joined: Sat Apr 21, 2007 12:03 am


Return to HTML Forum

Who is online

Users browsing this forum: No registered users and 4 guests