Using [removed] How to create a 'Go Back' link that takes the user to a link if there's no history for the tab or window?

前端 未结 12 1855
星月不相逢
星月不相逢 2020-12-12 21:36

EDIT-2: None of the answers seem to work. Not even the one I previously marked as the answer of this question. Any help is appreciated. Thanks.

12条回答
  •  -上瘾入骨i
    2020-12-12 22:11

    The reason on using the return:false; is well explained on this other question.

    For the other issue, you can check for the referrer to see if it is empty:

        function backAway(){
            if (document.referrer == "") { //alternatively, window.history.length == 0
                window.location = "http://www.example.com";
            } else {
                history.back();
            }
        }
    
    Back Button Here.
    

提交回复
热议问题