Javascript 一旦用户登录到JSF页面,禁用浏览器后退按钮
我在SpringWebFlow中使用了tiles。这是我的标准jsf文件 标准.xhtmlJavascript 一旦用户登录到JSF页面,禁用浏览器后退按钮,javascript,jsf,tiles,Javascript,Jsf,Tiles,我在SpringWebFlow中使用了tiles。这是我的标准jsf文件 标准.xhtml <f:view contentType="text/html"> <h:head > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Nagra Employee Leave Application</title> <
<f:view contentType="text/html">
<h:head >
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nagra Employee Leave Application</title>
<link rel="stylesheet" href="${request.contextPath}/styles/blueprint/screen.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${request.contextPath}/styles/blueprint/print.css" type="text/css" media="print" />
<link rel="stylesheet" href="${request.contextPath}/styles/le-frog/jquery-ui-1.8.2.custom.css" type="text/css" media="screen" />
<ui:insert name="headIncludes"/>
<style>
</style>
</h:head>
<h:body style="background:#343433" >
<div class="container" style="background:white;">
<a href="#{request.contextPath}"><img src="${request.contextPath}/images/rubon1.jpg" height="200" width="950" alt="Spring Travel"/></a>
<div>
<div id="local" class="span-4 colborder" style="padding-top: 20px;
padding-left: 21px;">
<h3>Nagra Vision</h3>
<ui:insert name="notes"/>
</div>
<div class="span-19 last" style="width: 720px;">
<ui:insert name="content"/>
</div>
</div>
<div>
<a href="http://www.nagra.com">
<img src="${request.contextPath}/images/nagra_footer.png" alt="Powered by Nagra-India" />
</a>
</div>
</div>
</h:body>
Login.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/layouts/standard.xhtml">
<ui:define name="content">
<h:form style="margin-top:10px;">
<div>
<h:outputLabel for="username">Username: </h:outputLabel>
<h:inputText id="username" value="#{userInfo.username}"> </h:inputText>
</div>
<div>
<h:outputLabel for="password">Password: </h:outputLabel>
<h:inputSecret id="password" value="#{userInfo.password}">
</h:inputSecret>
</div>
<div>
<h:selectBooleanCheckbox id="leavetype"
value="#{userInfo.loginperson}">
<f:selectItems value="#{referenceData.loginPersonOptions}" />
</h:selectBooleanCheckbox>
<h:outputLabel for="password">Select you are a manager</h:outputLabel>
</div>
<div>
<p:commandButton id="Signin" action="click" value="Sign In"
style="margin-left:80px;" />
</div>
</h:form>
</ui:define>
mainpage.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/layouts/standard.xhtml">
<ui:define name="notes">
<h:outputLabel for="employee">${loginperson.username}</h:outputLabel>
<h:form>
<div> <h:commandLink value="Sick Leave" action="sickleave" id="sickleave" /></div>
<div> <h:commandLink value="Paid off Leave" action="paidleave" id="paidleave" /></div>
<div> <h:commandLink value="Logout" action="logout" id="logout" /></div>
</h:form>
</ui:define>
<ui:define name="content">
<h2 style="font-size: 16px; font-weight: bold; margin-top: 100px;">Available
Leave</h2>
<h:dataTable value="#{leaveavailable}" var="a"
styleClass="order-table" headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
columnClasses="order-table-odd-column,order-table-even-column">
<h:column>
<f:facet name="header">
Sick Leave
</f:facet>
#{a.totalSickLeave}
</h:column>
<h:column>
<f:facet name="header">
Paidoff Leave
</f:facet>
#{a.totalPaidoffLeave}
</h:column>
</h:dataTable>
</ui:define>
在这里,一旦用户登录,用户将看到mainpage.xhtml。在用户进入mainpage之后,如果他按下浏览器的后退按钮,我将进入登录页面。因此我需要禁用后退按钮。我不知道在何处添加javascript代码来禁用浏览器后退按钮。无论我是否必须在mainpage.xhtml或standard.xhtml中添加
我必须添加什么java脚本来禁用后退按钮禁用后退按钮是不可能的-看一看,从用户体验的角度来看,这可能也是个坏主意,所以没有太大损失。尝试执行此操作被列为您不能禁用“后退”按钮。但是,您可以使用从浏览器历史记录中删除当前文档,并将其替换为所需的文档。请记住,在这种情况下需要使用AJAX,因为必须从要替换的文档中调用replace
与其干预JavaScript并试图破坏用户的浏览器,不如在服务器端检查用户是否已经登录并将其重定向到您的主页?如果适合您的情况,您可以尝试以下操作 通过设置正确的http无缓存技巧停止缓存页面,请参阅。 登录后,您将在会话中存储一些信息,因为当用户单击“上一步”按钮时,您不会缓存页面。新的请求将发送到服务器,在处理登录页面请求时,您可以检查,如果已经登录,则重定向到其他页面。 希望这有帮助
Just try this,it works fine for me :)
Disable Back functionality using history.forward
这是在任何网页中禁用back功能的另一种技术。我们可以通过在网页中添加以下代码来禁用反向导航。现在的问题是,您必须在所有希望避免用户从上一页返回的页面中添加此代码。例如,用户遵循导航页面1->page2。并且您要停止用户从第2页返回到第1页。在本例中,第1页中的所有以下代码
<SCRIPT type="text/javascript">
window.history.forward();
function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">
上述代码将触发page1的history.forward事件。所以,若用户按下第2页上的“后退”按钮,他将被发送到第1页。但是第1页上的history.forward代码将用户推回到第2页。因此,用户将无法从第1页返回。
查看在线演示-
您好,我可以知道如何在SpringWebFlow中执行重定向吗对不起,我不知道SpringWebFlow。也许你会在中发现一些有用的东西,否则请随意问一个关于swf中重定向的新问题不要忘记接受codebox的答案。