简体   繁体   中英

Redirecting to previous page

I have ASP.NET MVC5 page with .NET Framework. 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.

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();" 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.

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.

I also read about this and tried with including return false; but i couldn't help me to. How can i redirect users to previous page properly ?

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

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