How to trigger a js function with the browser back button??

Discussion in 'JavaScript' started by 123GoToAndPlay, Mar 17, 2010.

  1. #1
    Hi,

    I a bit stuck with jquery/ajax and the browser back button.
    Summary: i have a multiple search filter page, where the results are shown in an ajax div. Now each result row is clickable and a detailed page is shown.
    On this detailed page i have a go back link which finally works. The back link triggers a certain .js function, i would like to trigger this js function with the browser back button as well. Is this possible?

    regards
     
    123GoToAndPlay, Mar 17, 2010 IP
  2. RoyalFlushed

    RoyalFlushed Peon

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi 123GoToAndPlay,

    I don't think it is possible to check if the browsers back button is pressed.

    What you can do is put onbeforeunload in the body tag, like : <body onbeforeunload="yourFunction();">

    This will trigger if the page viewer leaves the current page, not only browser back, so this might not be what you are looking for.

    Good luck!
     
    RoyalFlushed, Mar 18, 2010 IP