real quick js question

D

DL

can't think straight,

How do self close the opened child window from the following code?
thank you. tried it with Firefox 3.5, didn't close the child window.

<form action="save.cfm" method="post">Your email: <input type="text"
name="email" id="email" size="30"> (optional)
<input type="button" id="sendEmail" value="Send" onclick="window.open
('save.cfm?email='+document.getElementById
('email').value,'savemail','width=150,height=150'); self.close();">
</form>
 
T

Thomas 'PointedEars' Lahn

DL said:
can't think straight,
Obviously.

How do self close the opened child window from the following code?
thank you. tried it with Firefox 3.5, didn't close the child window.

<form action="save.cfm" method="post">Your email: <input type="text"
name="email" id="email" size="30"> (optional)
<input type="button" id="sendEmail" value="Send" onclick="window.open
('save.cfm?email='+document.getElementById
('email').value,'savemail','width=150,height=150'); self.close();">
</form>

This can't work as intended because self.close() is roughly equivalent to
window.self.close() which is equivalent to window.close().

If you want to close the previously opened window, you need to do that in
'save.cfm?email='+document.getElementById('email').value (e.g. in the
`onload' event-handler code of its `body' element) because only there you
can safely say that this document has been loaded, i.e. that the server-side
action that it apparently triggers resulted in a response document. (You
could also regularly poll the documents load status from the opener window,
but you don't want to do that.)

You are coding functionality twice here, thus create a potential maintenance
nightmare (for example, your server-side script (here: save.cfm) needs to
handle both GET and POST requests with the same parameters, whereas
especially the GET part needs further protection or you have a potential
security leak there).

IMHO, your `onclick' event-handler code of the button should become
`onsubmit' event-handler code of the form, whereas in that `onsubmit' code
you would only open an empty window with an appropriate name and use that in
the `target' property value of the form, either statically or dynamically
(statically if you want to suggest a new window/tab regardless of whether
client-side scripting were available or not).


HTH

PointedEars
 
E

Evertjan.

DL wrote on 29 aug 2009 in comp.lang.javascript:
can't think straight,

How do self close the opened child window from the following code?
thank you. tried it with Firefox 3.5, didn't close the child window.

<form action="save.cfm" method="post">Your email: <input type="text"
name="email" id="email" size="30"> (optional)
<input type="button" id="sendEmail" value="Send" onclick="window.open
('save.cfm?email='+document.getElementById
('email').value,'savemail','width=150,height=150'); self.close();">
</form>

What is quick about this Q?
Is it important that a Q be quick?
 
D

Don84

This can't work as intended because self.close() is roughly equivalent to
window.self.close() which is equivalent to window.close().

If you want to close the previously opened window, you need to do that in
'save.cfm?email='+document.getElementById('email').value (e.g. in the
`onload' event-handler code of its `body' element) because only there you
can safely say that this document has been loaded, i.e. that the server-side
action that it apparently triggers resulted in a response document.  (You
could also regularly poll the documents load status from the opener window,
but you don't want to do that.)

You are coding functionality twice here, thus create a potential maintenance
nightmare (for example, your server-side script (here: save.cfm) needs to
handle both GET and POST requests with the same parameters, whereas
especially the GET part needs further protection or you have a potential
security leak there).

IMHO, your `onclick' event-handler code of the button should become
`onsubmit' event-handler code of the form, whereas in that `onsubmit' code
you would only open an empty window with an appropriate name and use thatin
the `target' property value of the form, either statically or dynamically
(statically if you want to suggest a new window/tab regardless of whether
client-side scripting were available or not).

HTH

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <[email protected]>

As I said, "can't think staight", silly me, resolved, just add the
event of close() upon load of the child window.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top