Page redirection based on an event

Discussion in 'Javascript' started by justaguy, Jul 30, 2011.

  1. justaguy

    justaguy Guest

    Hi,

    I wonder if there's a way to cause a page redirection based on an
    event of the current page.

    What I'd like to happen is:
    If the user does not click on the [Download] button I'll redirect him/
    her to a tips page, namely,
    the best-note-taking-tips-from-10-colleges.html file
    in the review directory

    My attempt is:
    include a hidden field named 'downloadChk' in the form of 'f'
    with default value of 0
    if the download button is clicked, change that field's value to 1
    (business role: in that case no need for redirection),
    then with the event of onbeforeunload at BODY element to determine the
    page redirection or not...

    Status:
    Not working

    Here's the page,
    http://www.knowledgenotebook.com/download_dev.html

    What am I doing wrong? How to fix it?

    Many thanks.
     
    justaguy, Jul 30, 2011
    #1
    1. Advertising

  2. justaguy

    Luuk Guest

    On 30-07-2011 20:33, justaguy wrote:
    > Hi,
    >
    > I wonder if there's a way to cause a page redirection based on an
    > event of the current page.
    >
    > What I'd like to happen is:
    > If the user does not click on the [Download] button I'll redirect him/
    > her to a tips page, namely,
    > the best-note-taking-tips-from-10-colleges.html file
    > in the review directory
    >
    > My attempt is:
    > include a hidden field named 'downloadChk' in the form of 'f'
    > with default value of 0
    > if the download button is clicked, change that field's value to 1
    > (business role: in that case no need for redirection),
    > then with the event of onbeforeunload at BODY element to determine the
    > page redirection or not...
    >
    > Status:
    > Not working
    >
    > Here's the page,
    > http://www.knowledgenotebook.com/download_dev.html
    >
    > What am I doing wrong? How to fix it?
    >
    > Many thanks.
    >


    my javascript skills are limited.... ;)

    but i have two suggestions:
    1)
    <body onbeforeunload="if (document.f.downloadChk.value=='0'){gotoTips();}">

    should be changed to:
    <body onbeforeunload="if (document.f.downloadChk.value=='0'){gotoTips();
    return false}">

    otherwhise the docuument is unloaded.....

    2)
    function gotoTips()
    {
    document.href.location='/review/best-note-taking-tips-from-10-colleges.html';
    }

    should be changed to:
    function gotoTips()
    {
    document.location.href='/review/best-note-taking-tips-from-10-colleges.html';
    }

    Because ther's no such thing as document.href.location.

    --
    Luuk
     
    Luuk, Jul 30, 2011
    #2
    1. Advertising

  3. 30.07.2011 21:33, justaguy wrote:

    > I wonder if there's a way to cause a page redirection based on an
    > event of the current page.


    Certainly, with the usual caveats

    > What I'd like to happen is:
    > If the user does not click on the [Download] button I'll redirect him/
    > her to a tips page,


    So you want something to happen in the _absence_ of an event. That's
    something completely different.

    You could set a timer and trigger some action if the user does not click
    on the button within some period of time. Usual and unusual caveats
    apply: WCAG 2.0 has a lot (mostly sensible things) to say about timed
    events and their accessibility problems.

    Or you could trigger an action if the user performs some action without
    having clicked on the button before that. This is almost trivial: use a
    logical variable and set it when the button is clicked on, then test
    that variable in the other event handler.

    > My attempt is:
    > include a hidden field named 'downloadChk' in the form of 'f'
    > with default value of 0
    > if the download button is clicked, change that field's value to 1


    I don't see why you would need a hidden field, or a form at all.

    > then with the event of onbeforeunload at BODY element to determine the
    > page redirection or not...


    Sounds like my second scenario.

    > http://www.knowledgenotebook.com/download_dev.html


    You have:

    function gotoTips()
    {
    document.href.location='/review/best-note-taking-tips-from-10-colleges.html';
    }

    It should have document.location and an absolute URL like
    http://www.knowledgenotebook.com/review/best-note-taking-tips-from-10-colleges.html

    But I'm not sure whether this is the way onbeforeunload is supposed to
    be used. At least it does not work that way on Firefox. Things change if
    the event handler returns a value.

    Even then, it's problematic. Trying to force people into going a
    specific page when they are about to leave your page in any way won't be
    a success, and it has technical problems as well.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Jul 30, 2011
    #3
  4. justaguy

    justaguy Guest

    On Jul 30, 4:12 pm, "Jukka K. Korpela" <> wrote:
    > 30.07.2011 21:33, justaguy wrote:
    > > I wonder if there's a way to cause a page redirection based on an
    > > event of the current page.

    >
    > Certainly, with the usual caveats
    >
    > > What I'd like to happen is:
    > > If the user does not click on the [Download] button I'll redirect him/
    > > her to a tips page,

    >
    > So you want something to happen in the _absence_ of an event. That's
    > something completely different.
    >
    > You could set a timer and trigger some action if the user does not click
    > on the button within some period of time. Usual and unusual caveats
    > apply: WCAG 2.0 has a lot (mostly sensible things) to say about timed
    > events and their accessibility problems.
    >
    > Or you could trigger an action if the user performs some action without
    > having clicked on the button before that. This is almost trivial: use a
    > logical variable and set it when the button is clicked on, then test
    > that variable in the other event handler.
    >
    > > My attempt is:
    > > include a hidden field named 'downloadChk' in the form of 'f'
    > > with default value of 0
    > > if the download button is clicked, change that field's value to 1

    >
    > I don't see why you would need a hidden field, or a form at all.
    >
    > > then with the event of onbeforeunload at BODY element to determine the
    > > page redirection or not...

    >
    > Sounds like my second scenario.
    >
    > >http://www.knowledgenotebook.com/download_dev.html

    >
    > You have:
    >
    > function gotoTips()
    > {
    > document.href.location='/review/best-note-taking-tips-from-10-colleges.html';
    >
    > }
    >
    > It should have document.location and an absolute URL likehttp://www.knowledgenotebook.com/review/best-note-taking-tips-from-10...
    >
    > But I'm not sure whether this is the way onbeforeunload is supposed to
    > be used. At least it does not work that way on Firefox. Things change if
    > the event handler returns a value.
    >
    > Even then, it's problematic. Trying to force people into going a
    > specific page when they are about to leave your page in any way won't be
    > a success, and it has technical problems as well.
    >
    > --
    > Yucca,http://www.cs.tut.fi/~jkorpela/


    Thank you both. It works with IE9 but not Firefox 3.6.18 nor Chrome
    12.
    IE9 setting for browsing history is "Every Time Loading the Page" (no
    cache)
    Firefox (unclear, however, the History option of changing the default
    (Remember History) to "Never remember history" does not help.
    Chrome does not even have such a setting...
     
    justaguy, Aug 5, 2011
    #4
  5. justaguy

    dhtml Guest

    On Jul 30, 1:12 pm, "Jukka K. Korpela" <> wrote:
    > 30.07.2011 21:33, justaguy wrote:


    [...]
    >
    > It should have document.location and an absolute URL

    document.location is proprietary.

    likehttp://www.knowledgenotebook.com/review/best-note-taking-tips-from-10....
    >
    > But I'm not sure whether this is the way onbeforeunload is supposed to
    > be used. At least it does not work that way on Firefox. Things change if
    > the event handler returns a value.
    >

    It isn't.

    > Even then, it's problematic. Trying to force people into going a
    > specific page when they are about to leave your page in any way won't be
    > a success, and it has technical problems as well.
    >

    Yep. It's a bad idea. Give the user a link instead; he'll click it if
    he wants to.
    --
    Garrett
     
    dhtml, Aug 7, 2011
    #5
    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. Neal
    Replies:
    2
    Views:
    380
    John Saunders
    Jun 19, 2004
  2. Cory  Lievers
    Replies:
    2
    Views:
    528
    Cory Lievers
    Feb 22, 2006
  3. VEIDEMANIS

    Login based Site redirection

    VEIDEMANIS, Jun 19, 2006, in forum: HTML
    Replies:
    4
    Views:
    462
  4. Thomas Fujita
    Replies:
    1
    Views:
    294
    Kenny
    Oct 22, 2003
  5. justaguy
    Replies:
    0
    Views:
    531
    justaguy
    Jul 31, 2011
Loading...

Share This Page