PDA

View Full Version : DHTML Window Widget Window Positioning



dbr00d
03-13-2010, 03:52 AM
1) Script Title: DHTML Window widget (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

3) Describe problem:
I've implemented this script on my site, and am interested in saving window positioning AFTER the page is refreshed. I have it all thought out, but am having a hard time figuring out how to retrieve a window's positioning. I've tried looking into the getviewpoint function, but can't quite see where the values (preferably coordinates) would come from. Any ideas?

dbr00d
03-13-2010, 04:53 AM
So, here's a start. This is what I've tried:

I created a getleft function to return t.lastx, which is generated in rememberattrs


getleft:function(t){
dhtmlwindow.rememberattrs(t)
return t.lastx //position window to last known x coord just before minimizing
},


Here's rememberattrs:


rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page
this.getviewpoint() //Get current window viewpoint numbers
t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left //store last known x coord of window just before minimizing
t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top
t.lastwidth=parseInt(t.style.width) //store last known width of window just before minimizing/ closing
},


But when I call this getleft function from my test page, I receive an undefined value.


var left = time.getleft();
alert(left); // undefined


Any help is greatly appreciated! All I want is to be able to retrieve these positioning values.

dbr00d
03-13-2010, 02:12 PM
'Still stuck. Any ideas, anyone?

ddadmin
03-13-2010, 11:38 PM
Actually to get the coordinates of a DHTML window, all you should have to do is probe the window object's left and top properties, and not t.lastx or t.lasty. So say you've opened a DHTML window using the code:


var googlewin=dhtmlwindow.open("googlebox", "iframe", "http://google.com", "Google Web site", "width=700px,height=450px,resize=1,scrolling=1,center=1", "recal")

To get this window's last x and y coordinates at anything, you can just do:


var xpos=googlewin.style.left
var ypos=googlewin.style.top

You may want to check out this thread (http://www.dynamicdrive.com/forums/showthread.php?t=29434), which contains an example of getting the last coordinates of a DHTML window and stores it in a cookie. When the same window is loaded on another page, those coordinates are used to reposition the window so they mirror the previous page's.