简体   繁体   English

Javascript返回页面加载

[英]Javascript go back on page load

I have a Wordpress site where there is a restricted page, and if the user navigates to this page but is not logged in, they get sent to a sign-up page. 我有一个Wordpress网站,那里有一个受限制的页面,如果用户导航到该页面但未登录,他们将被发送到注册页面。

If they log in using this form, they do get logged in but they stay on the same page showing the login form. 如果他们使用此表单登录,则他们确实会登录,但是他们停留在显示登录表单的同一页面上。

I want them to be able to log in and then when the page re-loads, they get sent to whichever restricted page they were previously trying to view. 我希望他们能够登录,然后在重新加载页面时,将它们发送到以前尝试查看的任何受限页面。

In my page template I have used: 在页面模板中,我使用了:

<?php if(!is_user_logged_in()) { ?>
show login form
<?php } else { ?>

<?php } ?>

And its the blank space where I need to put something to say if they ARE logged in then go back to previous page (before they got redirected for not being logged in). 其空白处是我需要登录的地方,然后返回上一页(在未登录之前被重定向)。

Thanks 谢谢

If I'm understanding your question, then I think the window.location javascript property is what you're looking for. 如果我了解您的问题,那么我认为window.location javascript属性就是您想要的。 Use it like so: 像这样使用它:

window.location = "http://myredirect.com"

See this post's top answer if you want some more information. 如果您需要更多信息,请参阅此帖子的最佳答案

If you really want to use the history back button, you can take a look at history.back() as referenced in this question and top answer . 如果您确实要使用历史记录后退按钮,则可以查看此问题和最佳答案中引用的history.back()

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

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