Stopping navigation away from the page

Discussion in 'Javascript' started by Yash, Jan 31, 2008.

  1. Yash

    Yash Guest

    Hi,

    In our ASP .NET application we present a form wherein the user has to
    input a number of fields. If in the middle of filling the form, the
    user accidentally navigates away from the page, either by clicking a
    link on the page or hitting an entry in the Favorites or in any way,
    we want to present an alert with only the OK button, which when
    clicked will keep the user on the same page and avoid the navigation
    out of the page.

    If we do it in the onbeforeunload event, we get a standard popup with
    OK and CANCEL. When Cancel is clicked, the user navigates away. We
    want to avoid this.

    Can you please suggest a way? Is there a way to capture the navigation
    event and suppress it?

    Thanks,
    Yash
    Yash, Jan 31, 2008
    #1
    1. Advertising

  2. Yash

    GArlington Guest

    On Jan 31, 5:22 am, Yash <> wrote:
    > Hi,
    >
    > In our ASP .NET application we present a form wherein the user has to
    > input a number of fields. If in the middle of filling the form, the
    > user accidentally navigates away from the page, either by clicking a
    > link on the page or hitting an entry in the Favorites or in any way,
    > we want to present an alert with only the OK button, which when
    > clicked will keep the user on the same page and avoid the navigation
    > out of the page.
    >
    > If we do it in the onbeforeunload event, we get a standard popup with
    > OK and CANCEL. When Cancel is clicked, the user navigates away. We
    > want to avoid this.
    >
    > Can you please suggest a way? Is there a way to capture the navigation
    > event and suppress it?
    >
    > Thanks,
    > Yash


    1) What is the point in presenting only one option "OK"? Are you
    working for early Microsoft (an error occurred - click "OK" to
    continue)?
    2) If the user does not have a choice then there is NO point in
    presenting the box, but you can still use std alert()
    3) If you put this script in onUnload event, your user will NEVER be
    able to leave the page, or are you going to put some code in Submit
    button onClick event to disable the onUnload code?
    GArlington, Jan 31, 2008
    #2
    1. Advertising

  3. Yash

    Stevo Guest

    Yash wrote:
    > If we do it in the onbeforeunload event, we get a standard popup with
    > OK and CANCEL. When Cancel is clicked, the user navigates away. We
    > want to avoid this.


    That sounds like a bad idea. Why would you want to not allow a user to
    leave ? I agree catching them and asking if they're sure they want to
    abandon what they were doing is a good idea, but preventing them from
    doing it doesn't sound sensible.
    Stevo, Jan 31, 2008
    #3
  4. Yash

    Yash Guest

    On Jan 31, 5:26 pm, Stevo <> wrote:
    > Yash wrote:
    > > If we do it in the onbeforeunload event, we get a standard popup with
    > > OK and CANCEL. When Cancel is clicked, the user navigates away. We
    > > want to avoid this.

    >
    > That sounds like a bad idea. Why would you want to not allow a user to
    > leave ? I agree catching them and asking if they're sure they want to
    > abandon what they were doing is a good idea, but preventing them from
    > doing it doesn't sound sensible.


    I want to present only an OK because the user should be made aware of
    why he is not being allowed to leave. When he cliks OK, he will be
    back on the page.

    There will be special flag set onclick of the Submit button to exempt
    it from the above check. So only on Submitting, the user will be able
    to leave the page.

    This is a client requirement and we have no control over it.
    Yash, Jan 31, 2008
    #4
  5. Yash

    GArlington Guest

    On Jan 31, 2:03 pm, Yash <> wrote:
    > On Jan 31, 5:26 pm, Stevo <> wrote:
    >
    > > Yash wrote:
    > > > If we do it in the onbeforeunload event, we get a standard popup with
    > > > OK and CANCEL. When Cancel is clicked, the user navigates away. We
    > > > want to avoid this.

    >
    > > That sounds like a bad idea. Why would you want to not allow a user to
    > > leave ? I agree catching them and asking if they're sure they want to
    > > abandon what they were doing is a good idea, but preventing them from
    > > doing it doesn't sound sensible.

    >
    > I want to present only an OK because the user should be made aware of
    > why he is not being allowed to leave. When he cliks OK, he will be
    > back on the page.
    >
    > There will be special flag set onclick of the Submit button to exempt
    > it from the above check. So only on Submitting, the user will be able
    > to leave the page.


    You (and your client) will find a lot of angry ex-customers who will
    just close the site window in order to never to come back.

    >
    > This is a client requirement and we have no control over it.


    You (as a developer) should suggest to your client that they should
    rethink their strategy - you can not trap free people and expect them
    to be happy about it.
    GArlington, Jan 31, 2008
    #5
  6. Yash

    Stevo Guest

    Yash wrote:
    > On Jan 31, 5:26 pm, Stevo <> wrote:
    >> That sounds like a bad idea. Why would you want to not allow a user to
    >> leave ? I agree catching them and asking if they're sure they want to
    >> abandon what they were doing is a good idea, but preventing them from
    >> doing it doesn't sound sensible.

    >
    > This is a client requirement and we have no control over it.


    I certainly don't feel fine offering the solution to that. I would feel
    bad if I told someone how to trap people in web pages and that was used
    for adware type tactics. I'll pass.
    Stevo, Jan 31, 2008
    #6
  7. Yash

    seani Guest

    On 31 Jan, 14:30, GArlington <> wrote:
    > On Jan 31, 2:03 pm, Yash <> wrote:
    >
    >
    >
    > > On Jan 31, 5:26 pm, Stevo <> wrote:

    >
    > > > Yash wrote:
    > > > > If we do it in the onbeforeunload event, we get a standard popup with
    > > > > OK and CANCEL. When Cancel is clicked, the user navigates away. We
    > > > > want to avoid this.

    >
    > > > That sounds like a bad idea. Why would you want to not allow a user to
    > > > leave ? I agree catching them and asking if they're sure they want to
    > > > abandon what they were doing is a good idea, but preventing them from
    > > > doing it doesn't sound sensible.

    >
    > > I want to present only an OK because the user should be made aware of
    > > why he is not being allowed to leave. When he cliks OK, he will be
    > > back on the page.

    >
    > > There will be special flag set onclick of the Submit button to exempt
    > > it from the above check. So only on Submitting, the user will be able
    > > to leave the page.

    >
    > You (and your client) will find a lot of angry ex-customers who will
    > just close the site window in order to never to come back.
    >
    >
    >
    > > This is a client requirement and we have no control over it.

    >
    > You (as a developer) should suggest to your client that they should
    > rethink their strategy - you can not trap free people and expect them
    > to be happy about it.


    True enough in an Internet app., a lot less clear-cut on an intranet.
    Personally I'd never use an internet site that insisted on trapping me
    in this way. On a private intranet where you're using DHTML/JS as a
    mechanism to front other business processes, it could be perfectly
    acceptable.

    A bit more context from the OP might help.
    seani, Jan 31, 2008
    #7
  8. GArlington wrote:
    > On Jan 31, 2:03 pm, Yash <> wrote:
    >> On Jan 31, 5:26 pm, Stevo <> wrote:
    >>> Yash wrote:
    >>>> If we do it in the onbeforeunload event, we get a standard popup with
    >>>> OK and CANCEL. When Cancel is clicked, the user navigates away. We
    >>>> want to avoid this.
    >>> That sounds like a bad idea. Why would you want to not allow a user to
    >>> leave ? I agree catching them and asking if they're sure they want to
    >>> abandon what they were doing is a good idea, but preventing them from
    >>> doing it doesn't sound sensible.

    >> I want to present only an OK because the user should be made aware of
    >> why he is not being allowed to leave. When he cliks OK, he will be
    >> back on the page.
    >>
    >> There will be special flag set onclick of the Submit button to exempt
    >> it from the above check. So only on Submitting, the user will be able
    >> to leave the page.

    >
    > You (and your client) will find a lot of angry ex-customers who will
    > just close the site window in order to never to come back.


    I think they will have a hard time doing that, as clicking close causes the
    event listener for the ' beforeunload` event to be executed. Those
    then-furious ex-customers will have to kill the browser process in order to
    continue working, which is why they are going to tell all their friends,
    collegues and family to avoid this stupid Web site like hell in favor of the
    plenty other ones out there that would be advertising the same thing, only
    in an accessible way.

    >> This is a client requirement and we have no control over it.

    >
    > You (as a developer) should suggest to your client that they should
    > rethink their strategy - you can not trap free people and expect them
    > to be happy about it.


    Full ACK.


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Jan 31, 2008
    #8
  9. Yash wrote:
    > If we do it in the onbeforeunload event, we get a standard popup with
    > OK and CANCEL. When Cancel is clicked, the user navigates away. We
    > want to avoid this.


    I think you mean when "OK" is clicked, the user navigates away. And you do
    want this, trust me.

    > Can you please suggest a way? Is there a way to capture the navigation
    > event and suppress it?


    Furtunately, there is not. Besides, the only thing the user has to do to
    for prison break is to disable client-side script support to a sufficient
    extent (if event present), and never come back again.

    You really want to rethink your approach.


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Jan 31, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Fitzpatrick
    Replies:
    0
    Views:
    1,723
    Mark Fitzpatrick
    Jun 25, 2003
  2. Tone Curtis
    Replies:
    3
    Views:
    4,507
    Tone Curtis
    Jun 10, 2004
  3. UJ
    Replies:
    9
    Views:
    5,849
    mallik
    Jul 22, 2005
  4. Laurahn
    Replies:
    3
    Views:
    892
    Steven Cheng[MSFT]
    Feb 6, 2007
  5. SpaceMarine
    Replies:
    0
    Views:
    363
    SpaceMarine
    Sep 16, 2008
Loading...

Share This Page