Page redirection based on an event

J

justaguy

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.
 
L

Luuk

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.
 
J

Jukka K. Korpela

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.

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.
 
J

justaguy

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.

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.

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...
 
D

dhtml

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top