我想在用户离开当前网页时执行一些vb.net
代码。我知道如何使用javascript
代码显示提醒,但正如我所说,我希望(例如)在Label
上显示消息或在database
之前保存一些信息显示javascript alert
。这是警告信息:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim message As String = "Good Bye"
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onbeforeunload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("')};")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
End Sub