473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Call a function when "Back" is clicked!

Hi, I was wondering if there's a way to call a function when a user presses on the "back" or "forward" buttons of the browsers.

What I want is, redirect the user to a new website (let's say thescripts.com), when he tries to click "back" , "forward', "Go", etc.... on my page.

Is that possible? And if yes, can you please tell me how to handle these actions, plus what actions are possible (for example I know that it's impossible to do this action when someone tries to close the browser), what about "Stop" , "Refresh", etc....

Regards,
Wassim
Aug 6 '07 #1
3 1553
mrhoo
428 256MB
javascript will allow you to capture an unload event in all modern browsers, and you cannot cancel it. Usually you use the response to update a cookie or terminate a session just before your visitor refreshes or navigates from the page.

Some browsers support a beforeunload event, which can throw up a confirmation dialog that forces the user to select whether to go ahead and leave- or refresh, or whatever he intended to do.

Any code you write will only be run if the user changes his mind and cancels his action and stays on the current page. This would be a real mess if you then redirect him somewhere else.

When a visitor wants to leave, let him go.
Aug 7 '07 #2
pbmods
5,821 Expert 4TB
Heya, Wassim.

There are certain ways of using cookies to check to see if the User used the back button....
Aug 7 '07 #3
acoder
16,027 Expert Mod 8TB
When a visitor wants to leave, let him go.
You're right especially in a case like this. I can add to this though:

When a visitor doesn't want to leave, don't let him go. In an app. I wrote once, the backspace key would send the user back to the previous page. I'd detect that because it was definitely an accident. I would only try to stop them from leaving the page if they had made a change.
Aug 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: George | last post by:
I am trying to set up a login-logout website. I have a cookie about the login status. I put it as logout once the logout link is clicked. And I put a little security check about the status of...
5
by: Dani | last post by:
Hello everybody, I have some code that disables form elements on body load, but I notice when I hit the "back" button, I need to re-enable the form elements (that is done by clicking on a radial...
5
by: Ma³y Piotruœ | last post by:
Hello, (Sorry for my english.) I am new to HTML/JavaScript/CSS. I would like to ask for help with such a problem: I need to create a href link working like "back" button (I know this is not...
2
by: VB Programmer | last post by:
I created a page which I am using to prevent the user from hitting the BACK button. I'll call it my "Auto Jump" page. When it is called it basically auto-redirects to a page specified in the...
2
by: Barry Fitzgerald | last post by:
I have a site that requires a large number of pages to complete the entry of all the information. The information collected also varies depending on some of the data entered. I would like to...
8
by: Coleen | last post by:
Yes, I know why would I want to create a back button when there is one on the browser? Because that's what the users want! they want a "Previous" button that they can click from any web page in...
0
by: Michael Nemtsev | last post by:
Hi, I need to stay on the current page even if user clicks "BACK" in browser. Opera is very stubborn in attemp of turning cached page off, and using current. Does anybody know the way how to say...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.