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 1860
星月不相逢
星月不相逢 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条回答
  •  眼角桃花
    2020-12-12 22:19

    check window.history.length or simply, history.length

    EDIT: some browsers start their history with 0, others with 1. adjust accordingly.

    if it has a value of 1, it means it's the first page in that window/tab - then you can have JS redirect you.

    
    
    Back
    

提交回复
热议问题