Log in

View Full Version : DHTML Window widget (v1.1) Move Window To Different Page



jsl2247
01-20-2009, 01:47 PM
1) Script Title: DHTML Window widget (v1.1)

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

3) Describe problem: OK, I would like to start out by saying this is an absolute awesome script. I had no problems getting it implemented and it was exactly what I was looking for. OK now for my my question? Is it possible to have this window move to different pages. Say I open it on a page and I go to a different page can I have this window automatically load with he same infor and to the same location I had it. I am putting some monitoring itmes in there that will correlate with graphical views and it would be nice if this window would follow me around throught the different pages. I am sure some kind of cookie or something, could someone help me out?

jsl2247
01-20-2009, 05:56 PM
Ok I used the method in this thread to get the positioning correct using this posting : http://www.dynamicdrive.com/forums/showthread.php?t=29434

Now if someone could help, I am using an ajax window and I would like the window if opened on the previous page to stay open on the next page with out having to click on a link or button.

Here is a spinet of my code and I am using the script from the post above.



<script type="text/javascript" src="script/dhtmlwindow1.js">
</script>
<body>
<h1>Here it is!!!!</h1>
<script type="text/javascript">
function openPopup(){
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "sample.html",
"Sample Popup Window", "width=300px,height=200px,left=1px,top=1px,resize=1,scrolling=1", "recal")
ajaxwin.onclose=function(){return window.confirm("Alright to close this window?")}
if (dhtmlwindow.getCookie("ajaxbox"))
ajaxwin.moveTo(dhtmlwindow.getCookie("ajaxbox").split(" ")[0], dhtmlwindow.getCookie("ajaxbox").split(" ")[1])
}

</script>
<ul>
<li><a href="#" onClick="openPopup()(); return false">Open Sample</a></li>
<li><a href="page2.jsp">Page 2</a></li>
</ul>
</body>


Thanks!!!!

ddadmin
01-21-2009, 05:35 AM
Hmm the exact solution really depends upon the details of what you have already. For example, initially, will the user have to click on a link to open the DHTML window (on any page), and if so, have the same window automatically appear on subsequent pages? Assuming that's your set up, the solution would go something like the below:

Firstly, you'll want to modify the setCookie() function inside the modified .js file with the changes in red, to make sure the cookie value persist across all directories within your domain:


setCookie:function(name, value){
document.cookie = name + "=" + value+"; path=/"
},

Then, on all relevant pages of your site, install the modified DHTML window script on these pages, including the openpopup() function you have above:


<script type="text/javascript">
function openPopup(){
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "sample.html",
"Sample Popup Window", "width=300px,height=200px,left=1px,top=1px,resize=1,scrolling=1", "recal")
ajaxwin.onclose=function(){return window.confirm("Alright to close this window?")}
if (dhtmlwindow.getCookie("ajaxbox"))
ajaxwin.moveTo(dhtmlwindow.getCookie("ajaxbox").split(" ")[0], dhtmlwindow.getCookie("ajaxbox").split(" ")[1])
}

</script>

At this point no DHTML window should pop up automatically. To get that to happen if/when a window cookie is detected, add the below script following the above:


<script type="text/javascript">
if (dhtmlwindow.getCookie("ajaxbox"))
openPopup()
</script>

That should be it, in theory anyway.

jsl2247
01-21-2009, 01:47 PM
Thanks DD, the code does pop up the window if the cookie is present, but if you close the window and go to the next page the cookie is obviously still there so the window opens. I am working on it right now will report back if I get it.

Ok Got it not I am going to work on two independent windows working.

Here is what I did

Add to Open Function in js file

this.setCookie("isWindowOpen", 1)
Add To CLose Fuction in js file

this.setCookie("isWindowOpen", 0)
Put in Body tag

<body onload="isOpen()">
Here is the updated scripts

<script type="text/javascript">
var ajaxwin = null
function openPopup(){
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "sample.html",
"Sample Popup Window", "width=300px,height=200px,left=1px,top=1px,resize=1,scrolling=1", "recal")
ajaxwin.onclose=function(){return window.confirm("Alright to close this window?")}
if (dhtmlwindow.getCookie("ajaxbox"))
ajaxwin.moveTo(dhtmlwindow.getCookie("ajaxbox").split(" ")[0], dhtmlwindow.getCookie("ajaxbox").split(" ")[1])
}
function isOpen(){
if (dhtmlwindow.getCookie("isWindowOpen")==1)
openPopup()
}

</script>

Hope this helps someone down the road!!!

jsl2247
01-22-2009, 12:46 PM
Ok so does anyone know oh to set a dynamic cookie? I will have to create cookies for each separate box now. I will work on it today and report if i get anything.

So to hold position I had to delete the isWindowOpen cookie set in the open and close functions in the js file. I assume I am going to have to create an argument so set the cookies for open and close section in the actual function. Here is a sample of to open a second window and have it hold position.


function openWindow2(){
win2=dhtmlwindow.open("ajaxbox2", "ajax", "sample2.html",
"Window 2", "width=400px,height=400px,left=50px,top=50px,resize=1,scrolling=1", "recal")
win2.onclose=function(){return window.confirm("Alright to close Window 2?")}
if (dhtmlwindow.getCookie("ajaxbox2"))
win2.moveTo(dhtmlwindow.getCookie("ajaxbox2").split(" ")[0], dhtmlwindow.getCookie("ajaxbox2").split(" ")[1])
}

Socapex 2K
07-29-2009, 04:15 PM
OK, so I've been through these threads and I'm stuck where jsl2247 was. Even if I close the popup, it will reappear one page reload. Obviously jsl's solution didn't work if you use many popups, so I'm stuck at point A. Also, if you minimize a popup, and reload the page, it doesn't keep it's minimized state, anyway to add that into the cookies?

So for the dynamic cookies, I will work on that in php. I'll try to output the script vars dynamically for any onclick= containing a popup function... I don't know if it's doable, but I'll give it a try. It might generate way to much code though, since I'll have a page where it is possible to open... drum roll... 1000 popus! Wooohooo.

Going back to learning javascript :)
Socapex 2K