How to enable browser back button disabled with js? - back-button

I have an issue like "after user login to the site if he logout then again if he clicks on browser back button then the previous page showing again instead of login page" for this issue I fixed it by using below js code:
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
The browser back button issue fixed but after adding the above js code I got new issue i.e. browser back button totally getting disabled, what if user wants to use browser back button to navigate through the site web pages? can anyone please tell me how to fix it? Thanks in advance.

Related

Open Modal Pop Up in Page Load MVC2

I am new to MVC. The project that I am working on is on MVC2. The current requirement is to open a modal popup after login. Basically after successful login, the user will be redirected to a landing page, where i have to do some checks if i find the value more than zero, I have to open a modal pop up with a dropdown asking to make a selection, else show the default View.
Can anyone help me regarding the same.
Thank you.
When you say,
where i have to do some checks if i find the value more than zero
Do you already have this value? Or do you need to get one? If you need to get one:
A quick way of doing this would be to use TempData.
In the controller that contains the method for logging in, where the login is successful you can add:
TempData["login"] = 1;
Then in your view add:
#if (TempData["login"] != null)
{
#*Display Modal*#
}
Do you need actually need help with the code of the modal?
You can see an example of a popup modal with a form here: https://jqueryui.com/dialog/#modal-form

Using browser back button to navigate between the website pages

I have search this but didn't get useful information. In my website I have a order processing scenario. currently I am using a "back" button on page to go to the previous order page. I want to go back through the browser back button. I want the code which I added in page back button can run when I use the browser back button.
How I achieve this..?
try like this
$(document).ready(function(){
$('a.back').click(function(){
parent.history.back();
return false;
});
});
here the link is the one on which click you want to go back
or even better
have a look at this
History.go can do that:
parent.history.go(-1);

is it possible to not reload user control when redirect to a page?

I have created a user control for side menu navigation and when user clicks on one of the item on a menu, it displays details of the company and information. Now it is redirecting to different page for each company using passing parameter (ex. company.aspx?ID=10) and everytime when I clicked, it refreshes whole page. I would like to keep side menu user control without refresh as there is a live search option.
Is this possible? or should I change opposite way to do it? should be the side menu in a page and company info in a user control??
If you want to do a proper way using Ajax, you'll need to change the entire site structure. Here is a quick and dirty way of doing it using jQuery.
<script>
$(document).ready(function () {
$("#left-pane a").click(function (e) {
e.preventDefault();
loadUrl($(this).attr("href"));
});
});
function loadUrl(url) {
$("#right-pane").load(url);
}
</script>
I think what you're talking about is partial page update, where, rather than posting and reloading the entire page, you only reload part of it.
Here's a good article: Understanding Partial Page Updates with ASP.NET AJAX

Login. form Back button post data

I am creating a login form using post method. It is working fine. The logout button work fine. But when I pressed back button the browser and reach the login page where user submit the id and password the resend option is there. Then it resend the id and password again.. How can I overcome the problem.
You need to simply redirect the user back to the first page using javascript or server side code. Don't rely on having to go back in history to get there.
you can't. why do you want to do this anyway? all you need to do is redirect users with a bit of javascript:
<script>
window.location = "http://www.yoursite.com/login"
</script>
<noscript>
Back to login page
</noscript>
the noscript tag is for people that disabled javascript or simply dont have it.

Clear the browsing history on submit button click

I have a page with a about 200 controls on it and Submit, Close , SavenClose and Cancel buttons. My requirement is to clear the browsing history once any of these buttons are clicked.
As of now I am redirecting the users to the Home Page once any of these buttons are clicked where the users can click on GoBack on the browser and come back to main page which I dont want to .
Can anyone help me achieving this , probably give me a start up code pls.
Thank you.
You can't
This functionality is specifically within the browser's domain, and can't be accessed via javascript. It is for this reason many banks and organisations log you out when clicking 'back'.
You can however request the browser to not cache your pages, so clicking back will result in a "Cannot find this page - you need to refresh" message, this may be a suitable solution for you and is widely used.
I'm not sure but I think it's not possible to have control over a user browser functionality like "delete history".
You could add this javascript on the top of each webpage:
window.history.forward(1);
The user's browsing history is theirs to control. The best you can do is ask to close the tab via Javascript on the page after they submit. You can do this via window.close()

Resources