Calling a code behind function on onbeforeunload event

L

lee_youjin

I needed to defect when the user is clicking the IE X button ( top
right). so I could execute the cleanup function.

I was able to detect it using onbeforeunload event. Now I need to call
the function in code behind from onbeforeunload event call.

but that is where I have a problem...

please refer my code below

my body tag - <body onbeforeunload = "X_close()">

Javascript - function X_close( ) { if ( window.event.clientX < 0 ||
window.event.clientY < 0) { alert("test") } }

Is there a way I can call Cleanup func from X_close func? or is there
some other way to do this.. Any help appreciated!!!!!!! Thanks!!!

In my post back I have the code below. but this doesn't work.... It
should work I think.

Dim Script As String

Script = "<script language=""javascript"" type=""text/javascript"">"

Script &= "function X_close() { alert(""KKKKK"");}"

Script &= "</script>"

If (Not IsClientScriptBlockRegistered("clientScript")) Then

RegisterClientScriptBlock("clientScript", Script)

End If

Cleanup function ( vb.net)

Private Sub Cleanup(ByVal LineID As Integer)

Dim resourceData As New ResourceMaterial

resourceData.cleanup(LineID)

End Sub
 
W

web.dev

I needed to defect when the user is clicking the IE X button ( top
right). so I could execute the cleanup function.

I was able to detect it using onbeforeunload event. Now I need to call
the function in code behind from onbeforeunload event call.

but that is where I have a problem...

please refer my code below

my body tag - <body onbeforeunload = "X_close()">

Javascript - function X_close( ) { if ( window.event.clientX < 0 ||
window.event.clientY < 0) { alert("test") } }

Is there a way I can call Cleanup func from X_close func? or is there
some other way to do this.. Any help appreciated!!!!!!! Thanks!!!

[snip]

Yes it's possible. Of course you would also know that vbscript would
only work on IE. But anyways, the following example shows that it
works:

<html>
<head>
<title>example</title>
</head>
<body>
<script type = "text/vbscript">
function vbFunc()
document.write("vbscript")
end function
</script>

<script type = "text/javascript">
function jsFunc()
{
document.write("javascript");
}

vbFunc();
</script>
</body>
</html>

Please make note of the order that they're in. The vbscript must come
first before you are able to call the function. Tested in IE6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top