JCWEBHOST
asked on
on browser close
Hey guys i like to know is it possiable to sent an email when the user choose to close the browser
i have this js on my asp c# page
i have this js on my asp c# page
<script type="text/javascript">
var hook = true;
window.onbeforeunload = function()
{
if (hook)
{
var x = document.getElementById('<%=lblArea.ClientID%>').innerText;
return 'You have not verified your Bed and Breakfast in '+ x +', are you sure you wish to navigate away from this page? email sent to close page without verify:';
}
}
function unhook()
{
hook=false;
}
</script>
now if they click leave the page it must execute c# code to send them an email
ASKER
how do i place function doSomething in my code below?
<script type="text/javascript">
var hook = true;
window.onbeforeunload = function()
{
if (hook)
{
var x = document.getElementById('<%=lblArea.ClientID%>').innerText;
return 'You have not verified your Bed and Breakfast in '+ x +', are you sure you wish to navigate away from this page? email sent to close page without verify:';
}
}
function unhook()
{
hook=false;
}
</script>
Hi...
Please put above code in before </script>
also put below code:
<body onunload="doSomething(even t);">
Please put above code in before </script>
also put below code:
<body onunload="doSomething(even
ASKER
like this?
<script type="text/javascript">
function doSomething(e)
{
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY)
{
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
if (posy < 0)
{
window.open('../emails.aspx', '_self');
return true;
}
}
document.onkeydown = keydown;
function keydown(evt)
{
if (!evt) evt = event;
if (evt.altKey && evt.keyCode == 115)
{
window.open("../emails.aspx", '_self');
}
}
</script>
<script type="text/javascript">
var hook = true;
window.onbeforeunload = function()
{
if (hook)
{
var x = document.getElementById('<%=lblArea.ClientID%>').innerText;
return 'You have not verified your Bed and Breakfast in '+ x +', are you sure you wish to navigate away from this page? email sent to close page without verify:';
}
}
function unhook()
{
hook=false;
}
</script>
ASKER
it not working :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey when i put this code in the script it does not work but when i take it out it works
var hook = true;
window.onbeforeunload = function()
{
if (hook)
{
var x = document.getElementById('<%=lblArea.ClientID%>').innerText;
return 'You have not verified your Bed and Breakfast in '+ x +', are you sure you wish to navigate away from this page? email sent to close page without verify:';
}
}
function unhook()
{
hook=false;
}
ASKER
and i have tested this code in google chrome, it does not work but work for IE
function doSomething(e)
{
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY)
{
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
if (posy < 0)
{
window.open('emails.aspx', '_blank');
return true;
}
}
document.onkeydown = keydown;
function keydown(evt)
{
if (!evt) evt = event;
if (evt.altKey && evt.keyCode == 115)
{
window.open("emails.aspx", '_blank');
}
}
Hi..
YEs its just rendering issue of browsers..
Sorry but right now i dont have solution for other browsers..
I will check it..
YEs its just rendering issue of browsers..
Sorry but right now i dont have solution for other browsers..
I will check it..
ASKER
thanks
Aren't you looking for the onunload event...?
<body onload="alert('Something');" onunload="alert('Otherthing');">
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for JCWEBHOST's comment #a38838872
for the following reason:
it works
Accepted answer: 0 points for JCWEBHOST's comment #a38838872
for the following reason:
it works
ASKER
thanks
function doSomething(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.s
posy = e.clientY + document.body.scrollTop
+ document.documentElement.s
}
if (posy < 0) {
window.open('../Forms/LogO
return true;
}
}
document.onkeydown = keydown;
function keydown(evt) {
if (!evt) evt = event;
if (evt.altKey && evt.keyCode == 115) { //CTRL+ALT+F4
window.open("../Forms/LogO
}
}
Now you can write your code in Logout.aspx to send an email