onbeforeunload Event - Reload to another page

K

klaus1

Hi,

I tried many times to redirect after a page is disabled, and the user
presses F5 or anything else.
Therefore I found the onbegforeunload event, which might be usefull.
I don't like any kind of message box, just if the user gets the page,
each keypress should redirect on another page.
Only the first request should be placed on the site.
My code:

<html>
<head>
<script type="text/javascript">

window.onbeforeunload= function(){
window.location.href('http://www.google.com');
}

</script>
</head>
<body>

timeout exceeded!
</body>

</html>

It does not work..
any suggestions for me without having a message box?
thanks,
Klaus
 
T

Thomas 'PointedEars' Lahn

klaus1 said:
I tried many times to redirect after a page is disabled, and the user
presses F5 or anything else.
Therefore I found the onbegforeunload event, which might be usefull.

A lot of other script-kiddies thought so, which is why browser vendors
eventually decided that the only thing a listener for that *proprietary*
event should be able to do is to ask the user if they really want to leave.
Thus you may return only a string value to indicate part of the text that
is used for that prompt.
I don't like any kind of message box, just if the user gets the page,
each keypress should redirect on another page.

Use server-side redirects.
Only the first request should be placed on the site.
My code:

Dump it.
[...]
window.onbeforeunload= function(){
window.location.href('http://www.google.com');
}

Users will not take kindly on your redirecting them just anywhere (even if
it is Google) just because you are incompetent enough to break your site on
restructuring (or whatever). Redirect to a superordered entity, e.g. the
home page, of your site if your must, better yet redirect to the new
location of the resource or respond with status code 410 (Gone).

<http://www.w3.org/QA/Tips/uri-choose> pp.


PointedEars
 
K

klaus1

klaus1 said:
I tried many times to redirect after a page is disabled, and the user
presses F5 or anything else.
Therefore I found the onbegforeunload event, which might be usefull.

A lot of other script-kiddies thought so, which is why browser vendors
eventually decided that the only thing a listener for that *proprietary*
event should be able to do is to ask the user if they really want to leave.  
Thus you may return only a string value to indicate part of the text that
is used for that prompt.
I don't like any kind of message box, just if the user gets the page,
each keypress should redirect on another page.

Use server-side redirects.
Only the first request should be placed on the site.
My code:

Dump it.
[...]
window.onbeforeunload= function(){
window.location.href('http://www.google.com');
}

Users will not take kindly on your redirecting them just anywhere (even if
it is Google) just because you are incompetent enough to break your site on
restructuring (or whatever).  Redirect to a superordered entity, e.g. the
home page, of your site if your must, better yet redirect to the new
location of the resource or respond with status code 410 (Gone).

<http://www.w3.org/QA/Tips/uri-choose> pp.

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

OK, can you tell me the way with the message box, so that I can
redirect after asking the user?
Thanks,
Klaus
 
T

Thomas 'PointedEars' Lahn

klaus1 said:
Thomas said:
klaus1 said:
I tried many times to redirect after a page is disabled, and the user
presses F5 or anything else.
Therefore I found the onbegforeunload event, which might be usefull.

A lot of other script-kiddies thought so, which is why browser vendors
eventually decided that the only thing a listener for that *proprietary*
event should be able to do is to ask the user if they really want to
leave. Thus you may return only a string value to indicate part of the
text that is used for that prompt.

[...]

OK, can you tell me the way with the message box, so that I can
redirect after asking the user?

<http://lmgtfy.com/?q=onbeforeunload>

Please trim your quotes to the relevant minimum.


PointedErs
 
K

klaus1

i need anything to redirect if the question is answered by pressing
the OK button.
how can I use an if / else for the choosen button?
window.location does not work...
thanks,
 
T

Thomas 'PointedEars' Lahn

klaus1 said:
i need anything to redirect if the question is answered by pressing
the OK button.

I told you to use a server-side redirect. How to do that is off-topic
here. Use the URI I have provided. Also, Google is your friend, and
further questions about this can be asked in
comp.infosystems.www.servers.ALL.
how can I use an if / else for the choosen button?

You cannot. If the user confirms, you can do the server-side redirect;
if not, you don't.
window.location does not work...

Told you.

BTW, "trim quotes to the relevant minimum" means to leave the parts of the
quotation that you are referring to, as seen before. It does _not_ mean to
remove all quotation. Also you need to use your Shift key appropriately.
Further disregard of those basic posting guidelines are going to cause your
postings to be ignored. You have been warned.

<http://jibbering.com/faq/#posting> pp.


PointedEars
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top