Two window opening issues.

  • Thread starter The Natural Philosopher
  • Start date
T

The Natural Philosopher

I've got two slight failuers in my knowledge here, and could do with
some help.

The situation in the first case is a window, which pops up a sub window
coupled to an onclick event.

Nothing to worry about there, but the subwindow then does its stuff and
causes the main window to refresh, also fine.

BUT if I then re-click on the main screen, I want to re-use the already
opened window. I.e to respawn it with a different GET variable to
display different data. I thought I had it working, but its unreliable.

This is the code called by the onlclick events.

var child1;
var child2;

function stock_click(type,id)
{
if(type=='CAT')
{
if(!child1 || child1.closed==true) // never bin opened or been closed
child1=
window.open("categories.php?nobanner=yes&category_id="+id,"_blank",
"height=600,width=1000,scrollbars=no,location=no,menubar=no,toolbar=no,status=no,resizable=yes");
else
child1.location.replace("categories.php?nobanner=yes&category_id="+id);
child1.focus();
}
else
{
if(!child2 || child2.closed== true) // see above..
child2=window.open("stockedit.php?nobanner=yes&id="+id, "_blank",

"height=768,width=1024,scrollbars=yes,location=no,menubar=no,toolbar=no,status=no,resizable=yes");
else child2.location.replace("stockedit.php?nobanner=yes&id="+id);
child2.focus();
}
}


The child window after updating the database calls this:-

function refreshParent()
{
if(opener!=null)
window.opener.document.forms[0].submit();
}

Forcing a reload of the main window.

I am wondering if this is what is causing the program to spawn multiple
windows instead of just one. I guess it must be as it will have wiped
out its 'knowledge' of what windows it has opened..

Any hints on how to achieve the desired activity would be most welcome.


The second problem is fairly simple conceptually.

I have a form, which when submitted,. may, depending on whats been
selected, need to cause a popup to appear to download a file.

So I select some data, and then click the go button, and I want a
download to appear.

I think I am correct in thinking this has to be a javascript browser
side thing? I cant suddenly turn a server side session into two sessions
by forking at the server?

I.e. my php script at the server cant fork() and spawn a subwindow? The
browser itself has to request a second window be opened with different
data yes?

If that is indeed true I think the answer is relatively simple: normally
when I hit the button I submit the forme loaded with its POST variables,
but in this case I need to call a second instance of it..will the POST
variables get passed even if an actual submit() has not been called? or
do I have to use get variables instead?
 
G

GArlington

I've got two slight failuers in my knowledge here, and could do with
some help.

The situation in the first case is a window, which pops up a sub window
coupled to an onclick event.

Nothing to worry about there, but the subwindow then does its stuff and
causes the main window to refresh, also fine.

BUT if I then re-click on the main screen, I want to re-use the already
opened window. I.e to respawn it with a different GET variable to
display different data. I thought I had it working, but its unreliable.
Use some window name (of your own choice) instead of "_blank" in
window.open()...
This is the code called by the onlclick events.

var child1;
var child2;

function stock_click(type,id)
{
if(type=='CAT')
  {
  if(!child1 || child1.closed==true) // never bin opened or been closed
   child1=
    window.open("categories.php?nobanner=yes&category_id="+id,"_blank",
        "height=600,width=1000,scrollbars=no,location=no,menubar=no,toolbar=no,status=no,resizable=yes");
   else
child1.location.replace("categories.php?nobanner=yes&category_id="+id);
                child1.focus();
                }
        else
                {
                if(!child2 || child2.closed== true) // see above..
                        child2=window.open("stockedit.php?nobanner=yes&id="+id, "_blank",

"height=768,width=1024,scrollbars=yes,location=no,menubar=no,toolbar=no,status=no,resizable=yes");
                else child2.location.replace("stockedit.php?nobanner=yes&id="+id);
                child2.focus();
                }

}

The child window after updating the database calls this:-

function refreshParent()        
       {
        if(opener!=null)
                        window.opener.document.forms[0].submit();
       }

Forcing a reload of the main window.

I am wondering if this is what is causing the program to spawn multiple
windows instead of just one.
target "_blank" in window.open() will ALWAYS open a NEW window...
With named target you do NOT need to store window refs...
I guess it must be as it will have wiped
out its 'knowledge' of what windows it has opened..

Any hints on how to achieve the desired activity would be most welcome.

The second problem is fairly simple conceptually.

I have a form, which when submitted,. may, depending on whats been
selected, need to cause a popup to appear to download a file.

So I select some data, and then click the go button, and I want a
download to appear.
Generate output with mime-type that is NOT handled by browser...
Or were you talking about JavaScript popup?
I think I am correct in thinking this has to be a javascript browser
side thing? I cant suddenly turn a server side session into two sessions
by forking at the server?

I.e. my php script at the server cant fork() and spawn a subwindow?
Correct... Only client (browser) can open new windows...
The
browser itself has to request a second window be opened with different
data yes? Yes.

If that is indeed true I think the answer is relatively simple: normally
when I hit the button I submit the forme loaded with its POST variables,
but in this case I need to call a second instance of it..will the POST
variables get passed even if an actual submit() has not been called? or
do I have to use get variables instead?
You will have to re-post (or use GET)...
 
T

The Natural Philosopher

GArlington said:
Use some window name (of your own choice) instead of "_blank" in
window.open()...

the problem is that it then opens in tabbed form, not a popup separate
window..
 
S

SAM

Le 12/9/08 6:31 PM, The Natural Philosopher a écrit :
the problem is that it then opens in tabbed form, not a popup separate
window..


In my Firefox as I fixed it :
(not saw with IE)

Popup :

window.open('page.htm','','width=500,height=400');
window.open('page.htm','sam','width=500,height=400');

Tab :

window.open('page.htm');
window.open('page.htm','');


What is working for me:
(after having refreshed his opener the popup tell him it is his son)

==========
= Mother :
==========

JS:
===
var child_1, child_2;
function pop1() {
if(!child_1 || child_1.closed)
child_1 = window.open('page.htm','sam','width=500,height=400');
child_1.focus();
}
function pop2() {
if(!child_2 || child_2.closed)
child_2 = window.open('page.htm','samy','width=500,height=400');
child_2.focus();
}

html:
=====

the target of the forms could be 'sam' and 'samy'


===========
= child 1 :
===========

JS:
===
var daughter;
function suivi() { opener.child_1 = self.window; }
function neu() {
if(opener) {
opener.location.reload();
daughter = setInterval('suivi()',200);
setTimeout('clearInterval(daughter)',5000);
}
return false;
}

html :
======
<a href="#" onclick="return neu()">refresh mother</a>

===========
= child 2 :
===========

JS:
===
var daughter;
function suivi() { opener.child_1 = self.window; }
function neu() {
if(opener) {
opener.location.reload();
daughter = setInterval('suivi()',200);
setTimeout('clearInterval(daughter)',5000);
}
return false;
}

html :
======
<a href="#" onclick="return neu()">refresh mother</a>
 
R

rf

The Natural Philosopher said:
the problem is that it then opens in tabbed form, not a popup separate
window..

That is a browser setting, beyond your control.

Stop farting around with new windows and your problems go away.
 
T

The Natural Philosopher

SAM said:
Le 12/9/08 6:31 PM, The Natural Philosopher a écrit :


In my Firefox as I fixed it :
(not saw with IE)

Popup :

window.open('page.htm','','width=500,height=400');
window.open('page.htm','sam','width=500,height=400');

Tab :

window.open('page.htm');
window.open('page.htm','');


What is working for me:
(after having refreshed his opener the popup tell him it is his son)

==========
= Mother :
==========

JS:
===
var child_1, child_2;
function pop1() {
if(!child_1 || child_1.closed)
child_1 = window.open('page.htm','sam','width=500,height=400');
child_1.focus();
}
function pop2() {
if(!child_2 || child_2.closed)
child_2 = window.open('page.htm','samy','width=500,height=400');
child_2.focus();
}

html:
=====

the target of the forms could be 'sam' and 'samy'


===========
= child 1 :
===========

JS:
===
var daughter;
function suivi() { opener.child_1 = self.window; }
function neu() {
if(opener) {
opener.location.reload();
daughter = setInterval('suivi()',200);
setTimeout('clearInterval(daughter)',5000);
}
return false;
}

html :
======
<a href="#" onclick="return neu()">refresh mother</a>

===========
= child 2 :
===========

JS:
===
var daughter;
function suivi() { opener.child_1 = self.window; }
function neu() {
if(opener) {
opener.location.reload();
daughter = setInterval('suivi()',200);
setTimeout('clearInterval(daughter)',5000);
}
return false;
}

html :
======
<a href="#" onclick="return neu()">refresh mother</a>

sam, many thanks. i'll study that tomorrow..too late now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top