dapperwaterbuffalo
dapperwaterbuffalo

Reputation: 2748

Is it possible to disable brower refresh capabilities with JavaScript?

The reason I ask such an odd question is that I currently am creating computer based test environment, and obviously in the test I have a live countdown timer. Unfortunately on refreshing the page the timer is reset :(.

Obviously I will be looking to involve some method of storing the start time server side so that it always starts the countdown from this. However in a test situation I want the user to be locked in essentially, so I want to know if I can disable the browser navigationg buttons like back and refresh.

Upvotes: 0

Views: 286

Answers (3)

Narendra Kamma
Narendra Kamma

Reputation: 1441

Not much control here, but did you try onUnload event of JavaScript.

<body onUnload='SaveCounterData();'> 

This event is supposed to execute, when the page is being unloaded. Why/How (back button/refresh/closing window) it is being unloaded is not important here.

Upvotes: 0

The Surrican
The Surrican

Reputation: 29856

No, you cant.

There are only some nasty ways involving an alert message that has to be confirmed (works in most browsers).

In a real environment you should work with some server side logging based on account/ip and/or cookies.

In a test environment you could give the user a specific browser without that funcitonality. Firefox offers that in form of prism.

Upvotes: 4

Gareth
Gareth

Reputation: 138012

Not unless you can give the user a browser which has had that functionality removed

Upvotes: 0

Related Questions