Computer
Computer

Reputation: 2227

Close pop-up from code behind

I have two sites (both within my control)

Site 1 - opens a pop-up on Site 2. To open the popup on site 2 i have the below

Dim strPopup As String = "<script language='javascript' ID='script1'>" + "window.open('" & http://site2.com/customer.aspx" & ",'pop', 'top=90, left=200, width=1000, height=800, dependant=no, location=0, alwaysRaised=no, menubar=no, resizeable=no, scrollbars=no, toolbar=no, status=no, center=yes')" + "</script>"

ScriptManager.RegisterStartupScript(DirectCast(HttpContext.Current.Handler, Page), GetType(Page), "Script1", strPopup, False)

Note: the 'pop' within the code above is the name of the form according to my understanding.

So far this works as expected.

Site 2 displays the pop-up from above and has a button on it. I would like to close the popup/window opened above so tweaked the above script and added it to the button event in code behind on site 2

Dim strPopup As String = "<script language='javascript' ID='script1'>" + "window.close" + "</script>"

ScriptManager.RegisterStartupScript(DirectCast(HttpContext.Current.Handler, Page), GetType(Page), "Script1", strPopup, False)

but this doesnt work. Ive tried

pop.close (pop is the name given to the form on the first code i posted)

I'm a little lost on how to close the open window within a button event in code behind (please note within the pop-up the user is saving data when they click this button so the idea is to close the button once they click the Save button)

Upvotes: 1

Views: 2750

Answers (1)

feeeper
feeeper

Reputation: 3017

window.close is a function. You should use window.close() (with round brakets) instead of window.close.

Upvotes: 2

Related Questions