How to disable browser back button on home page in javascript - javascript

How can we disable browser back button on home page if session is active.Same like Facebook site functionality??

In Javascript
$(document).ready(function() {
function disableBack() { window.history.forward() }
window.onload = disableBack();
window.onpageshow = function(evt) { if (evt.persisted) disableBack() }
});
Read this document

Related

How to call a function written in Snippet after redirecting the current window to a link (eg. window.location = "https://google.com")

this.testing = function(link) {
window.location = link;
window.addEventListener('load', function() {
alert("It's loaded!");
});
//OR
myFunctionCall()
}
This is the code I'm trying to implement but after the window is redirected to a link Im not getting the alert.
My aim is to call a function which is dependent on the window after getting redirected

cross domain issues prevent action when reload parent page

I'm trying to reload the parent page from another domain. I achieved the reload on parent page when closing the child, but once I reload, the action on onclick event triggers again. My question is how can I prevent window.open once it reloads?
This is the code:
// here I've added `return false` but it fails to prevent the popup
<asp:HyperLink ID="HyperLink1" runat="server" onclick="return myopen('https://www.example.org/applicant/getdrivers?ApplicantId=15647&type=0', 'VieworUploadDocs','toolbar=no,location=no,directories=no,status=no,menubar=no,position=center,width=700px,height=850px');return false;" Text="Click Here" />
The script:
<script type="text/javascript">
//open window
var myWindow = null;
var myTimer = null;
myopen = function (url) {
myWindow = open(url, 'VieworUploadDocs', 'toolbar=no,location=no,directories=no,status=no,menubar=no,position=center,width=700px,height=850px');
myTimer = setInterval(function (e) {
if (myWindow == null || myWindow.closed) {
alert('Please wait while page loads.');
location.reload();
clearInterval(myTimer);
e.stopPropagation();
}
}, 5000);
}
</script>
I've also tried putting this in my code:
return false;
e.preventDefault();
e.stopPropagation();

Trouble with pagecontainer (jQuery Mobile)

I'm developing an app with PhoneGap but there is an issue. I have a log in form, and, as it is very simple, I'm sending the login information on the URL.
So, that's what happens: User puts username -> jQuery changes the page to logged_in.html (pagecontainer) and then loads www.example.com/logged.php?user=USERNAME_ON_FORM.
However, the logged_in.html page does load, but somehow it is keeping the old page, so I have to scroll down to see the logged in page. Is there anyway to work this out?
I tried this but it disabled everything.
$(document).bind("mobileinit", function () { $.mobile.ajaxEnabled = false; });
Here it is my code:
var $ = jQuery.noConflict();
$(document).ready(function(){
function init() {
document.addEventListener("deviceready", deviceReady, true);
delete init;
}
$("#loginForm").on("submit",function(e) {
var u = $("#username", this).val();
if(u != '') {
// $.mobile.changePage("logged_in.html");
$("body").pagecontainer("change", "logged_in.html" );
setTimeout(function(){
$('#logged_teste').load('http://example.com/app/model/login_dados.php?email='+u);
},1000);
}
return false;
});
});
I'm searching for anything I can do but nothing works...

Is it possible to navigate to particular URL on window.unload?

Is it possible to navigate to particular URL on window.unload?
Something like below.......target browser is chrome and safari.
$(window).on('beforeunload', function () {
window.location.href = "default.aspx";
});
Add this to the <head> tag.
<script>
window.onbeforeunload = function () {
window.location = 'http://www.example.com';
return false;
}
</script>
Or if you have an external js, that'd do too.

how to call a logout code after runs onbeforeunload

have something like this in my main page:
<script language="javascript">
window.onbeforeunload = function(evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
</script>
What I want to do is call my logout piece of code in order to free all resources, but only if the user press leave page bottom, is that possible... know witch option did the user choice?
Thank you all, best regards
use the onunload event:
window.onunload = function () {
// your logout code
};
var myclose = false;
$(window).on('beforeunload', function(){
var messege = 'You have closed the browser. Do you want to logout from your application?';
setTimeout('myclose=false',10);
myclose=true;
return myclose;
});
$(window).on('onunload', function(){
if (myclose==true)
{
//the url of your logout page which invalidate session on logout
alert('hello');
location.replace('logout.php') ;
}
});
var myclose = false;
$(window).on('beforeunload', function(){
var messege = 'You have closed the browser. Do you want to logout from your application?';
setTimeout('myclose=false',10);
myclose=true;
return myclose;
});
$(window).on('onunload', function(){
if (myclose==true)
{
//the url of your logout page which invalidate session on logout
alert('hello');
location.replace('logout.php') ;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Categories