Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

browser ie and firefox

Status
Not open for further replies.

onressy

Programmer
Joined
Mar 7, 2006
Messages
421
Location
CA
I need to use a JS where i disable the back button for a quiz that users are taking. any suggstions?
 
maybe instead it could be detected if the user returned to the previous page, then i could use:
window.history.forward(1);

what the best approach to check if the user has previously been to that page (in IE /FF)

Thanks!!!
 
It's hard to do this because some browsers will cache pages they open and so hitting the back button would actually load the page from the local cache rather than (re)obtain it from the server.

One idea I just thought of while typing this, is to use Ajax. Cached or not, the browser would have to re-execute the ajax code. Look into how to use ajax. When you grab the file, have the JavaScript append a random number in the query string so the browser won't cache the response.

Code:
// assuming "ajax" holds your XmlHttpRequest object
ajax.open ("GET", "realdata.cgi?" + Math.floor(Math.random()*99999), true);

Your handler for getting the data back from the CGI could simply document.write the page received.

This way, your "realdata.cgi" will be requested each time the user runs that JavaScript (either their first visit to the page or by clicking the back button), and the CGI could be programmed to log temporary data to see how many times the user has requested that CGI file.

has a good lil tutorial on ajax to get you started.
 
A simpler solution is to open the quiz in a new window which doesn't have the toolbars, so the back button isn't there to click. People could still hit Backspace or Alt+Left to go back though, but it would make it harder for the average user who doesn't know these shortcuts.

They could also right-click and click "Back" but if you disable right-clicking, it solves that problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top