LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2007, 02:15 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
javascript - how do you redefine the browser's back button?


Quick description:
I've built a page with a shopping-cart-like ...err... cart. Users add things to their cart via a POST form. They then go to an overview of their cart & have the ability to do stuff to the cart. It's very likely that the user will look at their cart, then go back and choose more items to put in it.

The problem:
If a users adds something to the cart, then views the cart, then clicks the browser's back button to add more items, the browser tries to repost the data & displays that pesky "the previous page has post data" message. This is what I'm trying to avoid.

I tried reloading the page via php code:

header($_SERVER['REQUEST_URI']);

but I still get the same message when trying to go back.

My idea then was to redefine the back button so rather than going back in history, it goes to a new page that is the last page without POST vars.

I know there is the "window.onbeforeunload" javascript event & that I could do it in there, but that will do the same thing for all navigation away from that page - some of which could be valid.... so I only want to handle the actual back button.

any ideas? preferably simple ones.

Last edited by BrianK; 10-26-2007 at 02:40 PM.
 
Old 10-26-2007, 08:06 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
While I would still know how to redefine the back button (which I don't think is possible from my research in the mean time), I was able to solve the problem by resending the header:

header('Location: '.$_SERVER['REQUEST_URI']);

.. just have to send all the removable data through POST vars & the nav data through GET vars. This way, the GET vars stay in tact, but the POST vars are removed.

interesting anecdote: While searching google a couple hours ago, one of the first page returns was *this* page. only 3-4 hours old & already searchable through google. weird.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript:Combobox creation taking data from DB On button click Manashi Programming 5 03-12-2015 02:38 AM
Unable to create box with button click ...using Javascript Manashi Programming 7 03-29-2006 11:48 PM
[javascript] confirm button on php page Erhnam Programming 1 02-24-2005 01:05 PM
can javascript automatically populate login fields and click button for me? opioid Programming 1 02-16-2005 03:58 PM
Say goodbye to Back button jetblackz Linux - Software 17 10-18-2002 12:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration