Logout once the Browser is Closed - javascript

I'm trying to record user sign out time in mysql DB once he close the browser. I searched for it but the most articles talking about window.onbeforeunload JavaScript event, but doesn't work with all browsers. even it works with F5 button can't specify massage or action,.
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">
<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>
test by redirecting
<script>
function myFunction() {
return "specific massage";
}
</script>
</body>
</html>

Related

prevent user from clicking browser's back button

I want to disable the browser's back button. I have tried some javascript codes to implement the same. But those codes didn't meet my requirements. It works in firefox but not working in chrome and edge. Sometimes it works all the three but randomly working and not working.
Can anybody share me the script disable the back button in all browsers without flaws like random behaviour.
Here I showed some scripts I have tried
history.pushState(null, null, window.location.href);
history.back();
window.onpopstate = () => history.forward();
history.pushState(null, null, location.href);
history.back();
history.forward();
window.onpopstate = function () { history.go(1); };
You can refer to the following code. I test the code sample in Edge, Chrome and Firefox, it works well.
Save this file as a.html for the first page:
<!DOCTYPE html>
<html>
<head>
<title>First Page</title>
<script type="text/javascript">
function preventBack() {
window.history.forward();
}
setTimeout("preventBack()", 0);
window.onunload = function () { null };
</script>
</head>
<body>
<h3>This is first page</h3>
Goto second Page
</body>
</html>
Save this file as b.html for the second page:
<!DOCTYPE html>
<html>
<head>
<title>
Blocking Back Button using javascript
</title>
</head>
<body>
<h3>This is second page</h3>
<p>
On this page, back button functionality is disabled.
</p>
</body>
</html>
Run a.html and click to navigate to b.html. Then click browser's back button on b.html, it won't navigate to a.html.

Close current window when it call Open Tel:

When I call window.location.href("tel:"+'+0060199999') it will open the Skype which is working fine.But i dont want current browser window stay open, i want to close it.If i put close, it is not even open the Skype.Is this possible to do?
<html>
<script>
window.onload = function () {
window.location.href="tel:+0060199999";
window.close();
}
</script>
<body>
Let me test
</body>
</html>

Javascript window close

I need to get a custom alert box when user clicks on 'X' (window close).
User is given 'OK' and 'Cancel' button options
OK button closes the window. Cancel button cancels the close action
I think you may find your answer on this post which looks similar - javascript confirm dialog box before close browser window
You have to show what you have done so far
Html code
<html>
<head>
<script type="text/javascript">
window.onbeforeunload = function() {
return "Did you save your stuff?"
}
</script>
</head>
<body>
</body>
</html>

How to auto press ok on javascript alert

I want to code the javascript alert so when a message is displayed, the OK button is automatically pressed.
HTML
<html>
<script language=javascript>
function rdir()
{
alert("Please wait while the page is redirected!");
window.location="/alarms_act_lat.htm";
}
</script>
<body onLoad=rdir()>
<center>
<h1>LATCHED ALARMS ARE CLEARED</h1>
</center>
</body>
</html>
That's not possible – at least, not without a browser extension. All JavaScript execution in the browser stops during alert().

Is it possible to take the FB share dialog and after a user has shared, to then post a message to the users?

For example, the dialog below will open a new window to share from. After the window is closed out because the user has shared the post. Could you then do a overlay message from the original url using javascript?
http://www.upworthy.com/if-you-live-in-one-of-these-states-the-impact-of-washingtons-shenanigans-is-huge
The site above does something like this, just not sure how. If you click on share to facebook and then "x" out of the box, you'll see a overlay that happens after a user has either shared or closed the window. Is this done with javascript, if so how?
<a class="shareonfb" style="color: #fff;text-indent: 0px;padding-left: 35px;width: 130px;padding-top: 10px;height: 24px;" onClick="window.open (this.href, 'child', 'height=400,width=665,scrollbars'); return false" href="https://www.facebook.com/sharer/sharer.php?u=http://foo.com" target="_blank">Share on Facebook</a>
create a html file "parent.html" and put the code:
<!DOCTYPE html>
<html>
<head>
<script>
function open_win()
{
myWindow=window.open('popup.html','','width=300,height=250');
myWindow.focus();
myWindow.onbeforeunload = WindowCloseHanlder;
}
function WindowCloseHanlder(){
myWindow.close();
window.alert('Popup is closed');
}
</script>
</head>
<body>
<h1>Welcome to my Home Page</h1>
Share on Facebook
</body>
</html>
create "popup.html" and put this code:
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>I am pop up</h1>
<p>Close this window</p>
</body>
</html>
You will see the javascript call after you close the popup window. Instead of alert message you can call your popup.

Categories