简体   繁体   中英

How to redirect to login page after page refresh

I am using jQuery mobile for my application and java at the server side. The user has to be redirected to the login page, ie index.html, if the user presses refresh button.

Can this be done using JavaScript or do I need to add java code to achieve it?

With JavaScript you can only handle the onbeforeunload event. 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. I don't even know if this is possible in the onbeforeunload event, but I would recommend you fix it server side. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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