Popup box without reload when activated from a different url.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kaster
    New Member
    • Nov 2008
    • 6

    Popup box without reload when activated from a different url.

    I am using the script below on several webpages, to pop up a window where people can order some things. It works well when shifting forth and back between the same page from where it is activated.
    But when it is reactivated from another page on the website the popup is reloaded and things written here dissapear. Is there a way to avoid the popup to reload and only come into focus when clicked from another page?

    Code:
    [  <script type="text/javascript">
    //<![CDATA[var foo=null; function focusfoo(){if (foo&&!foo.closed) foo.focus();}
    function blurfoo(){ if (foo&&!foo.closed) foo.blur();} //]]>
    </script>
    <a href="javascript:void(0)" onclick="foo=window.open('popuppage.htm','win4','width=700,height=460,top=11,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false" onfocus="foo;" onmouseover="focusfoo();"></a>  ]
    Thank you.
    Karsten
    Last edited by acoder; Nov 10 '08, 06:51 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    When you change the page, the reference to the pop-up window will be lost. You can use the pop-up window to re-establish it by using window.opener to refer to its parent window.

    Comment

    • Kaster
      New Member
      • Nov 2008
      • 6

      #3
      Originally posted by acoder
      When you change the page, the reference to the pop-up window will be lost. You can use the pop-up window to re-establish it by using window.opener to refer to its parent window.
      Can´t make it work. How should I put it? Tried ....

      Code:
      <a href="javascript:void(0)" onclick="foo=window.open('popuppage.htm','win4','width=700,height=460,top=11,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false" window.opener="parent();" onmouseover="focusfoo();"></a>
      ....and...

      Code:
      <a href="javascript:void(0)" onclick="foo=window.open('popuppage.htm','win4',window.opener='parent','width=700,height=460,top=11,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false" onmouseover="focusfoo();"></a>
      ......but they still reload the popup box.
      Thanks again.
      Karsten

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        window.opener would be used from the popup window, not from the parent. One idea is to periodically check the parent for a reference to the popup using setInterval. If it doesn't exist, reset the variable foo to the popup window.

        Comment

        • Kaster
          New Member
          • Nov 2008
          • 6

          #5
          Originally posted by acoder
          window.opener would be used from the popup window, not from the parent. One idea is to periodically check the parent for a reference to the popup using setInterval. If it doesn't exist, reset the variable foo to the popup window.
          I don´t know how to write this Acoder. I have rewritten the script to look like this:
          Code:
          <script type="text/javascript">
          //<![CDATA[
          function pop() { 
          if (!foo) 
          foo=window.open('boks.htm','win4','width=700,height=460,top=11,left=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); 
          else foo.focus(); 
          } 
          var foo=null; function focusfoo(){if (foo&&!foo.closed) foo.focus();}
          function blurfoo(){ if (foo&&!foo.closed) foo.blur();} 
          //]]></script>
          
          <a href="boks.htm" target="boks" 
          onclick="pop();return false" onMouseOver="focusfoo()";>Stil spørgsmål til os.</a>
          You can see it in function http://es-masseovne.dk/side1.htm

          When clicked and reclicked from the same page, it does not reload the pop. But when the same link is clicked from other page the popupform is still reloaded (reset).

          Karsten

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You need to add code in the pop-up window, not the parent window to allow the parent to re-establish the reference.

            For example:
            Code:
            setInterval(testFoo,5000); // every five seconds
            function testFoo() {
                if (!window.opener.foo) {
                    window.opener.foo = self;
                }
            }
            Haven't tested, but just an idea.

            Comment

            • Kaster
              New Member
              • Nov 2008
              • 6

              #7
              Originally posted by acoder
              You need to add code in the pop-up window, not the parent window to allow the parent to re-establish the reference.

              For example:
              Code:
              setInterval(testFoo,5000); // every five seconds
              function testFoo() {
                  if (!window.opener.foo) {
                      window.opener.foo = self;
                  }
              }
              Haven't tested, but just an idea.
              Acoder you rock!
              It did the trick. Thanks a lot, I appreciate your great assitance.
              Karsten :-))))))

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                You're welcome. Glad it worked.

                PS. You may also want to add a check for window.opener in case the parent window has been closed (unless you close the child window when the parent is closed).

                Comment

                Working...