using javascript to mark a link as visited

前端 未结 5 1584
孤独总比滥情好
孤独总比滥情好 2020-12-06 01:17

FF2 (at least) doesn\'t mark as link as :visited if it triggers the onclick handler without following the href. I\'m using onclick to fetch data from a server and modify th

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 01:38

    Here is how I did it. Only works in browsers that support HTML5 history api.

    // store the current URL
    current_url = window.location.href
    
    // use replaceState to push a new entry into the browser's history
    history.replaceState({},"",desired_url)
    
    // use replaceState again to reset the URL
    history.replaceState({},"",current_url)
    

    Using replaceState means that the back button won't be affected.

提交回复
热议问题