Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop up without reload from new URL

Status
Not open for further replies.

051058

Technical User
Nov 17, 2008
2
I have this script to popup a form on my page.
When clicked (and reclicked) from the same page, it works fine. But when the same link is clicked from another page the popupform is reloaded and what has been written is all gone. How can I avoid the reload and just bring the window in focus again when the formlink is clicked from another page? See it in function
...
<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>
.......

Thanks Karsten
 
I think what you may want to consider trying is this:

Code:
...
<script type="text/javascript">
//<![CDATA[
function pop() { 
if (!foo) {
  // always (attempt to) open foo, but don't specify a URL just yet
  foo = window.open(null,'win4','width=700,height=460,top=11,left=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');

  if (!foo.contentWindow.document.getElementsByTagName(*)) {
    // foo has no content yet, so give it a URL 
    foo.url = 'boks.htm';
  }
  // make sure to bring foo to the front/focus
  focusfoo();
} 
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>

Basically, it always attempts a call to window.open(), with the same name "win4", but doesn't give a URL right away. If the window with that name is already created, this window.open() will essentially be ignored, otherwise the empty window will be created as desired.

Then, you check for any contents in the popup window (only works if the popup will be a document on the same domain as your parent page -- cross-domain security and all). If the popup window is empty, then set it's URL. Call focus to bring either the newly loading window (or the existing content) to the foreground focus.
 
Thanks Shadedecho.

Your proposal might also work. I did come around it
though by putting this script in the popup header:
....
<script type="text/javascript">setInterval(testFoo,1000); // every 1 seconds
function testFoo() {
if (!window.opener.foo) {
window.opener.foo = self; } }
</script>
....
It does excactly what I want.
But thank you for attempted help :)
Regards Karsten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top