SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to identify the browser back event

    Is there way to identify the browser back event in javascript.

    Regards
    Schumy

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by schumy View Post
    Is there way to identify the browser back event in javascript.

    Regards
    Schumy
    Hi Schumy!
    Welcome to sitepoint forums.

    Do you mean javascript:history.go(-1);? This will bring you to the previous page.
    HTML Code:
    <a href="javascript:history.go(-1);">Go Back</a>
    Umm i am not sure i got your question or not.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hi ragu

    the said event is been handled manually by the code, but what i want is to handle when the browser back from browser itself gets called,is there anyway, to capture that event.

    Thanks
    Schumy

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, there's not. Well, that's not entirely true -- You can use document.onunload, but moving in the history is not really an event on the document -- it's something, which handled in the browser and so is outside the scope of javascript (Which is tied to a document).
    Chances are, that you're trying to do something, which you shouldn't try in the first place. What is it, that you want to do?

  5. #5
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exact Scenario:

    Need to clarify,

    There is page called, http://<somesite>.html which contains, a form to submit
    when the form gets submitted, it gets redirected to another page say http://<nextpage_site>.html.

    Now what i want to handle, when i click the back button of the browser i should get the first url id.,[http://<somesite>.html]. Can the browser back event can be handled. I am not using any back link in my html forms to get back to the previous page. All I need to handle is from the browser back.

    Regards
    Schumy

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can prevent the repost-problem (Browser gives an ugly dialogue-box, when you press back, after post), by doing redirect-after-post (Also known as PRG). In the script, which is the target of the form (The action attribute), send a HTTP redirect, after the request has been processed, leading to the final page. The browser will not put the page in the history, if it responds with a redirect.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •