mcgants
asked on
Close javascript window in code
Hello,
I have written a script in my application that opens a popup calendar as follows:
Dim myScript As String = "<script language='JavaScript'>wind ow.open('C alendar.as px?ReturnT o=" & txtStartDate.ID & "', 'cal','width=180,height=16 0,left=270 ,top=180') ;</script> "
RegisterStartupScript("pop upCal", myScript)
This part works fine, and the window closes when the user clicks a date. The problem I am having is that I want to close the window when the user exits the page. I have tried using a function linked to onBodyUnload and a direct script (below) but neither work - failing as a Javascript error stating that the object 'cal' is undefined.
Dim myScript As String = "<script language='JavaScript'>cal. close();</ script>"
RegisterStartupScript("clo seCal", myScript)
Any help with my existing solution or an alternative would be greatly appreciated.
Cheers,
mcg
I have written a script in my application that opens a popup calendar as follows:
Dim myScript As String = "<script language='JavaScript'>wind
RegisterStartupScript("pop
This part works fine, and the window closes when the user clicks a date. The problem I am having is that I want to close the window when the user exits the page. I have tried using a function linked to onBodyUnload and a direct script (below) but neither work - failing as a Javascript error stating that the object 'cal' is undefined.
Dim myScript As String = "<script language='JavaScript'>cal.
RegisterStartupScript("clo
Any help with my existing solution or an alternative would be greatly appreciated.
Cheers,
mcg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks both, appreciated :D
Dim myScript As String = "<script language='JavaScript'>neww indow = window.open('Calendar.aspx ?ReturnTo= " & txtStartDate.ID & "', 'cal','width=180,height=16 0,left=270 ,top=180') ;</script> "
RegisterStartupScript("pop upCal", myScript)
' add this in your opener window's body tag
<body onunload="if(false == newwindow.closed) newwindow.close();">
RegisterStartupScript("pop
' add this in your opener window's body tag
<body onunload="if(false == newwindow.closed) newwindow.close();">
https://www.experts-exchange.com/questions/20630658/onUnload-Close-PopUp-Window.html?query=onunload+close+popup&topics=87