Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Page redirection based on an event

Reply
Thread Tools

Page redirection based on an event

 
 
justaguy
Guest
Posts: n/a
 
      07-30-2011
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.

 
Reply With Quote
 
 
 
 
Luuk
Guest
Posts: n/a
 
      07-30-2011
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
 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      07-30-2011
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/rev...-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/
 
Reply With Quote
 
justaguy
Guest
Posts: n/a
 
      08-05-2011
On Jul 30, 4:12*pm, "Jukka K. Korpela" <(E-Mail Removed)> 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...

 
Reply With Quote
 
dhtml
Guest
Posts: n/a
 
      08-07-2011
On Jul 30, 1:12*pm, "Jukka K. Korpela" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page redirection based on an event trigger justaguy Javascript 0 07-31-2011 03:29 PM
Login based Site redirection VEIDEMANIS HTML 4 06-19-2006 09:55 PM
.NET forms authentication role-based redirection? Cory Lievers ASP .Net 2 02-22-2006 04:55 PM
Determining in EndRequest event when redirection has occurred Neal ASP .Net 2 06-19-2004 01:07 AM
Maintaining session and auth. ticket from page to page redirection Thomas Fujita ASP .Net Mobile 1 10-22-2003 06:56 AM



Advertisments