467,887 Members | 1,568 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,887 developers. It's quick & easy.

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?

Expand|Select|Wrap|Line Numbers
  1. [  <script type="text/javascript">
  2. //<![CDATA[var foo=null; function focusfoo(){if (foo&&!foo.closed) foo.focus();}
  3. function blurfoo(){ if (foo&&!foo.closed) foo.blur();} //]]>
  4. </script>
  5. <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>  ]
  6.  
Thank you.
Karsten
Nov 10 '08 #1
  • viewed: 2649
Share:
7 Replies
acoder
Expert Mod 8TB
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.
Nov 10 '08 #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.
Can´t make it work. How should I put it? Tried ....

Expand|Select|Wrap|Line Numbers
  1. <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...

Expand|Select|Wrap|Line Numbers
  1. <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
Nov 11 '08 #3
acoder
Expert Mod 8TB
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.
Nov 11 '08 #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.
I don´t know how to write this Acoder. I have rewritten the script to look like this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. function pop() { 
  4. if (!foo) 
  5. 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'); 
  6. else foo.focus(); 
  7. var foo=null; function focusfoo(){if (foo&&!foo.closed) foo.focus();}
  8. function blurfoo(){ if (foo&&!foo.closed) foo.blur();} 
  9. //]]></script>
  10.  
  11. <a href="boks.htm" target="boks" 
  12. 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
Nov 18 '08 #5
acoder
Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. setInterval(testFoo,5000); // every five seconds
  2. function testFoo() {
  3.     if (!window.opener.foo) {
  4.         window.opener.foo = self;
  5.     }
  6. }
Haven't tested, but just an idea.
Nov 18 '08 #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:
Expand|Select|Wrap|Line Numbers
  1. setInterval(testFoo,5000); // every five seconds
  2. function testFoo() {
  3.     if (!window.opener.foo) {
  4.         window.opener.foo = self;
  5.     }
  6. }
Haven't tested, but just an idea.
Acoder you rock!
It did the trick. Thanks a lot, I appreciate your great assitance.
Karsten :-))))))
Nov 20 '08 #7
acoder
Expert Mod 8TB
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).
Nov 20 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

21 posts views Thread by Eugene | last post: by
5 posts views Thread by Hemanth | last post: by
6 posts views Thread by mkobus | last post: by
1 post views Thread by jeffrobbins | last post: by
11 posts views Thread by Alex.Svetos | last post: by
1 post views Thread by Raffi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.