By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

Popup box without reload when activated from a different url.

P: 6
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
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
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

P: 6
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 15k+
P: 16,027
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

P: 6
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 15k+
P: 16,027
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

P: 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 15k+
P: 16,027
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.