简体   繁体   English

页面刷新后如何重定向到登录页面

[英]How to redirect to login page after page refresh

I am using jQuery mobile for my application and java at the server side. 我在服务器端将jQuery mobile用于我的应用程序和java。 The user has to be redirected to the login page, ie index.html, if the user presses refresh button. 如果用户按下刷新按钮,则必须将用户重定向到登录页面,即index.html。

Can this be done using JavaScript or do I need to add java code to achieve it? 可以使用JavaScript完成此操作,还是需要添加Java代码才能实现?

With JavaScript you can only handle the onbeforeunload event. 使用JavaScript,您只能处理onbeforeunload事件。 But you don't know if the user refreshes or navigates away. 但是您不知道用户是刷新还是离开。 You need localstorage or cookies to keep your state and check if the user refreshes so you can redirect them. 您需要localstorage或cookie来保持您的状态,并检查用户是否刷新,以便您可以重定向它们。 I don't even know if this is possible in the onbeforeunload event, but I would recommend you fix it server side. 我什至不知道在onbeforeunload事件中是否有可能,但是我建议您在服务器端修复它。 You need to have some logic server side.For example keep the last page in session and if it equals the new page redirect to your index.html. 您需要有一些逻辑服务器端,例如将最后一页保留在会话中,如果它等于新页,则将其重定向到index.html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM