I have created a custom controller which is used to login into salesforce community. loginPage = Site.login(username,password, startUrl); loginpage.setRedirect(true); return loginPage;

My problem is when user click the Back arrow from home page in web browser it is going back to login page. I need to restrict this action how i can achieve this.

Thank, IRaj.


I'm not sure if I understand the use case here but I believe you can't reliably block a user from hitting the browser back button. You can prompt them using JavaScript

window.onbeforeunload = function() { return "Do you want to log out?"; };

You can find alternate approaches for handling this in JavaScript here.


It is difficult to disable the browser back button functionality for all the browser while you can prevent it using following javascript.

function preventBack(){window.history.forward();} setTimeout("preventBack()", 0); window.onunload=function(){null};

You may also check

if(UserInfo.getUserType() == 'Guest') return new PageReference('/CommunityLogin'); else new PageReference('/CommunityHome');

  • Hi Gaurav &Vikas , Thanks for your reply. I dont want to disable the back button in browser. when user successfully logged into the salesforce community it goes to user landing page. My problem is when user gives login page file name is address bar it is going to login page(Don't ask why your are giving the file in in address bar its a part of testing). My requirement is if he goes to login page he should not come back to User home page.
    – Tamil
    Jan 6 '15 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.