Asked  7 Months ago    Answers:  3   Viewed   12 times

How to disable browser's BACK Button (across browsers)?

 Answers

15

This question is very similar to this one...

You need to force the cache to expire for this to work. Place the following code on your page code behind.

Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
Tuesday, June 1, 2021
 
nfechner
answered 7 Months ago
95

This is working perfectly. i used the following to clear the cache. and i'm invalidating the session in logout.jsp, when clicked, it checks for some token attribute (which is set when the user logs in), and if it doesn't find it, it redirects to the login page.

<%

response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
    if(session.getAttribute("token")==null){
    response.sendRedirect(request.getContextPath() + "/LogOut.jsp");

}
%>

thanks for the suggestion though. I will certainly put it into action. every help and suggestion is appreciated.

Thursday, August 5, 2021
 
Nasir
answered 4 Months ago
13

You can write some javascript to do this. Here I have two examples, note that I only tested this on Chrome

Example 1 will return a message upon activation of the back button within the browser

rm(list = ls())
library(shiny)
jscode <- 'window.onbeforeunload = function() { return "Please use the button on the webpage"; };'
ui <- basicPage(
  mainPanel(tags$head(tags$script(jscode)))
)

server <- function(input, output,session) {}
runApp(list(ui = ui, server = server))

enter image description here

Example 2 will disable navigation altogether. Personally I don't like this method as people might be annoyed that your site doesn't offer standard navigation functionalities

rm(list = ls())
library(shiny)
jscode2 <- "history.pushState(null, null, document.title);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.title);});"
ui <- basicPage(
  mainPanel(tags$head(tags$script(jscode2)))
)

server <- function(input, output,session) {}
runApp(list(ui = ui, server = server))
Monday, August 30, 2021
 
uiroshan
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share