Forum Moderators: open

Message Too Old, No Replies

Closing browser onClick

onClick close

         

williamlsteele

4:43 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



I've got a tiny window that will be used to forward people to a Paypal account. How can I close the window with this code without getting a popup from the OS?

[codes]<form name="form1" method="post" action="">
<label>
<input onClick="window.close();" type="submit" name="Submit" value="Submit">
</label>
</form>
[/codes]

rocknbil

6:11 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your new window is created using a Javascript open method, it shouldn't give you a warning. (?)

However, the submit will still try to submit unless you return false on the form, also submit is not a valid name for a form object:

<form name="form1" onSubmit="return false;">
<input onClick="window.close();" type="submit" name="SubmitButton" value="Submit">
</form>

or, in this application, you **could** just use a button:

<form name="form1">
<input onClick="window.close();" type="button" name="SubmitButton" value="Submit">
</form>

The label tag is not necessary for a button, labels are an accessibility tag that informs readers what form object the label refers to:
<label for="email">Email:</label> <input type="text" name="email">

But if you're doing what I think you're doing, what you want is to forward the MAIN page to payPal via this small window. In which case:

in the main page:

<a href="somepage.html" onClick="newWin('somepage.html'); onClick="return false;">Click me</a>

. . . where "newWin" is whatever javascript function that opens your window. From the new window (somepage.html) this main page is referred to as the window.opener:

<form name="form1">
<input onClick="closeAndRefresh();" type="button" name="SubmitButton" value="Submit">
</form>
<script type="text/javascript">
function closeAndRefresh() {
if (window.opener &&!window.opener.closed) {
window.opener.document.location='https//www.paypal.com';
window.close();
}
}
</script>

Which should send the original opening page to paypal and close this window.

(sorry too much coffee this AM . . . .)