473,785 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

redirect to another page when browser back button is clicked

6 New Member
Hi,

I am trying to redirect the user to another page (other than the previous one in the browser's history) when the browser's (IE's) BACK button is clicked. I found this snippet, but am finding it difficult in getting it to run :(

Expand|Select|Wrap|Line Numbers
  1. if (history.previous)
  2. {
  3.     document.location="page_to_go_bak_to.html";
  4. }
  5.  
Could any of you please provide a small example for the code in page2 and where it should be placed (since I am a novice :))?
scenario: user goes from page1 to page2, when he clicks on browser BACK button in page2 he goes to page_to_go_bak_ to.html instead of page1.

thanks.
Mar 12 '08 #1
4 28865
vee10
141 New Member
hi,

u should write in page2 for the unload event

for example
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title>Untitled Page</title>
  4.    <script type="text/javascript">
  5.    function func()
  6.    {
  7.    if(window.history.previous) 
  8.    {
  9.    window.navigate('HTMLPage.htm');
  10.    }
  11.    }
  12.    </script>
  13. </head>
  14. <body onunload="func()">
  15.  
  16. </body>
  17. </html>
  18.  
then it will be redirected to HTMLPage.htm
Mar 12 '08 #2
gits
5,390 Recognized Expert Moderator Expert
you should use:

Expand|Select|Wrap|Line Numbers
  1. window.location.href = 'page_to_go_back_to.html';
instead of window.navigate () since this is not a standards-compliant method ...

kind regards
Mar 12 '08 #3
valhalen
6 New Member
ok..i have now tried both of your suggestions - neither seems to be working
so here's my code
=============== ====page1.html= =============== ===========
[HTML]<html>
<head>
<script>
function nextPage()
{
window.location .href = "page2.html "

}
</script>
<form name="next_page ">
<tr>
<td align="bottom">
<form method="POST">
<p><input type="button" name="B1" value="Go to Next Page" onclick="nextPa ge()" style="position :absolute; top:450px; left:607px"></p>
</form>
</td>
</tr>
</form>
</head>
<body>
</body>
</html>[/HTML]
=============== =============== =============== ============

=============== ====page2.html= =============== ===========
[HTML]<html>
<head>
<title>Untitl ed Page</title>
<script type="text/javascript">
function func()
{
if(window.histo ry.previous)
{
window.location .href = 'page_to_go_bac k_to.html';
}
}
</script>
</head>
<body onunload="func( )">

</body>
</html>[/HTML]
=============== =============== =============== ==========

=============== =======page_to_ go_back_to.html ===============

[HTML]<html>
<head>
<title>Page to go bak to</title>
</head>
<body>
</body>
</html>[/HTML]
=============== =============== =============== =========

please suggest - thank you.
Mar 12 '08 #4
valhalen
6 New Member
UPDATE - the below code when put in page2.html works, but when I hit "cancel" on the dialog box, it refreshes the page2 - can this be prevented? thank you.

[HTML]<head>
<script language="Javas cript">
<!--
function onBak()
{
var chk_message = "do you want to continue?";
var times = 0;
if (times == 0)
{
var leave = confirm(chk_mes sage);
window.location .href = 'page_to_go_bac k_to.html';

if (!leave)
location = self.location;
times++;
}
}

//-->
</script>
</head>
<body onunload="onBak ()">[/HTML]
Mar 12 '08 #5

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

Similar topics

2
587
by: Dot net work | last post by:
Hello. I have an aspx page that changes an HTML label's text using javascript. After the label's text has been changed in this way, I redirect to another aspx page. If I then use the back button on the browser, the label has lost it's newly changed value.
1
1798
by: ticars | last post by:
I have a web page which all it does is redirect a user to a different page (the page to redirect to is based on a database lookup). I want to make it so that when a user tries to use the back button, they don't rehit the redirect page. Is this possible? I know Response.Redirect won't do it, I tried Server.Transfer but received errors. Any ideas?
3
5029
by: 4psite | last post by:
I am creating (using php) an html page with many links. Clicking on a link open the link as _self. Clicking on the browser back button brings the prv html page (with the links,) but instead of getting it from the cache it will recreate it. My questiosn, how to avoid the re-creation of the php/html page and just to reload it from the cache. Coby
0
1973
by: neeraj | last post by:
Hi Everybody I have one problem in my asp.net web application. The problem is that I check the date validation in code behind; if user not gives the valid data and press save button then I fire my own exception by JavaScript alert message Through register startup script Like RegisterStartupScript("Startup", "<script language=javascript>
5
3008
by: ns21 | last post by:
How can the browser back button be disabled If the form is submitting information to other pages or submitting to itself or using redirections. I tried the tweaks like history.forward(1) in each page to prevent user to navigate back but its not very effective. The server side scripting is done using ASP. you may ask that why at first place I want to disable the browser back
7
2489
by: nkodali | last post by:
Hi, I am having a signup.asp page where a user enters his details and clicks on subscribe button. I am doing server side validation to check if the user already exists in the database and then allowing him to subscribe using VB script. This subscription will send an email and then redirect to a thank you page once the user is validated. Now my problem is when I hit the browser back button on thankyou.asp page it just flashes the signup.asp...
8
2479
by: wish | last post by:
Dear all, I would to ask that why the user always faced the different page when user click the back button instead back to page2.php but it go to page5.php..I remember in asp, we use the global.asa to solve this problem because the server will confuse when many user login the system as a member and every members go different pages. So may i have anyone to guide me?
1
1969
by: bharu | last post by:
I have 2 pages where i have submit button on 1st page & on 2nd page i have previous button. Both the time i post the data means submit the forms two times. But when i clicked 2nd page's browser back button i get 1 st page with the data but if i click on 1st page's browser back button i get the Warning: Page has Expired. Can any one tell me the solution for? Also i have tried the header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");...
8
3896
rrocket
by: rrocket | last post by:
I have a form that has various tables that are hidden. When the user selects a number from the DDL the corresponding number of tables shows up (using javascript). When the submit button is clicked it carries the values to the next page. The issue is when the user clicks the browser back button the page only shows 1 table (default setup) and not the 3 or 4 it had when it send to the next page. Is there a way to get the page to keep the...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.