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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing browser window on click 3

Status
Not open for further replies.

boatdrinks

IS-IT--Management
Jun 18, 2004
51
US
I am using this code to close the browser window when button2 is clicked, but it only works after I click the button twice. I have tried putting it in the Page_Load, and in the If(Not Ispostback) and If(Ispostback). I have also tried putting it in the Sub button2_click, which runs a few other things and still the same problem.

Button2.Attributes.Add("onClick", "javascript:self.close();")

 
Have you checked the HTML output to see if the script is being rendered before you actually click the button? If not, check the HTML once the page loads - don't do anything else.

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
This is the html


<input type="submit" name="button2" value=" Assign " onclick="javascript:self.close();if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="button2" />
 
Ok,

Is there a reason that you have "if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();" in there?

Try taking that out... see if it works. Also, I'm assuming that this is a pop-up window, not the root window? If you're trying to close the root window, you may run into problems.

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Have you tried window.close? if main window it will state "are you sure" if a "popup" it will just close it
 
the correct version would be:
Code:
Button2.Attributes.Clear();
Button2.Attributes.Add("onClick", "try { window.opener = this; window.close();} catch (e) {};");

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top