Results 1 to 6 of 6

Thread: DHTML Window widget (v1.1) Move Window To Different Page

  1. #1
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default DHTML Window widget (v1.1) Move Window To Different Page

    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?

  2. #2
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ok I used the method in this thread to get the positioning correct using this posting : http://www.dynamicdrive.com/forums/s...ad.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.

    Code:
      <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!!!!

  3. #3
    Join Date
    Aug 2004
    Posts
    9,918
    Thanks
    3
    Thanked 969 Times in 957 Posts
    Blog Entries
    15

    Default

    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:

    Code:
    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:

    Code:
            <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:

    Code:
    <script type="text/javascript">
    if (dhtmlwindow.getCookie("ajaxbox"))
     openPopup()
    </script>
    That should be it, in theory anyway.
    DD Admin

  4. The Following User Says Thank You to ddadmin For This Useful Post:

    jsl2247 (01-21-2009)

  5. #4
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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
    Code:
    this.setCookie("isWindowOpen", 1)
    Add To CLose Fuction in js file
    Code:
    this.setCookie("isWindowOpen", 0)
    Put in Body tag
    Code:
    <body onload="isOpen()">
    Here is the updated scripts
    Code:
       <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!!!
    Last edited by jsl2247; 01-21-2009 at 05:38 PM.

  6. #5
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.

    Code:
     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])
                }
    Last edited by jsl2247; 01-22-2009 at 01:47 PM.

  7. #6
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •