简体   繁体   English

重定向到上一页

[英]Redirecting to previous page

I have ASP.NET MVC5 page with .NET Framework. 我有带有.NET Framework的ASP.NET MVC5页面。 4.5. 4.5。

I have a page with several labels representing users details and also i have 2 buttons - back button which call JavaScript function onClick=" redirectToPreviousPage(); " and i have 1 button - Confirm. 我有一个带有多个标签的页面,这些标签代表用户详细信息,并且我还有2个按钮- 返回按钮 ,该按钮调用JavaScript函数onClick =“ redirectToPreviousPage(); ”,并且我有1个按钮-确认。

Confirm button open up a modal pop-up with few check boxes and from there users can thick them and accept the provided details with another button, called accept . 确认按钮打开一个模式弹出很少复选框,并从那里用户可以厚他们,接受另一个按钮所提供的细节,称接受

There are 4 possible pages from where users can navigate to this particular Details page and when they click back it calls "redirectToPreviousPage();" 有来自用户可以浏览到这个特定的详细信息页面,当他们点击返回调用4个可能的页面“redirectToPreviousPage();” function: 功能:

function redirectToPreviousPage() {
    debugger;
    var previousUrl = document.referrer;
    if (previousUrl !== window.location.href) {
        window.location.href = previousUrl;
    } else {
        history.go(-1);
        return false;
    }
}

If users skip Confirmation and click Back document.referrer works correct and it redirect the users to the page they came from. 如果用户跳过Confirmation并单击Back document.referrer可以正常工作,它将用户重定向到他们来自的页面。

The problem is when users click on Confirm button and click Accept on modal dialog window.referrer point to it's self and i want to avoid that. 问题是,当用户单击“ 确认”按钮,然后在模式对话框窗口上单击“ 接受” 。引荐指向其自身,我想避免这种情况。 For this purpose i'm using history.go(-1) even (-2) which should work fine, but it's not - even when URL is different than current URL and different from document.referrer URL returning to previous page isn't work. 为此,我使用了history.go(-1)甚至(-2)都可以正常工作,但事实并非如此-即使URL与当前URL不同且与document.URL无关,返回上一页也不是工作。

I also read about this and tried with including return false; 我还阅读了有关此内容,并尝试包含return false; but i couldn't help me to. 但我无能为力。 How can i redirect users to previous page properly ? 如何将用户正确地重定向到上一页?

为什么不存储以前的URL并在表单帖子或Cookie中将其传递,然后为首次访问提供默认值

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

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