Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2012, 01:58 PM   PM User | #1
prachippp
New Coder

 
Join Date: Jun 2011
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
prachippp is an unknown quantity at this point
code for how to restrict refresh page for online exam in javasript

i want to restrict refresh option for online examination can any one give me solution as early as possible .....please

I have written below script for timer

when i refresh the page timer is reset again.

<script type="text/javascript">
var settimmer = 0;
$(function(){
window.setInterval(function() {
var timeCounter = $("b[id=show-time]").html();
var updateTime = eval(timeCounter)- eval(1);
$("b[id=show-time]").html(updateTime);

if(updateTime == 0){
$("div[id=my-timer]").html("").html("Page redirecting........");
window.location = ("welcome.php");
}
}, 1000);

});
</script>

// Body Part
<div id="my-timer">

Page Will Redirect with in <b id="show-time">1800</b> seconds
</div>



Thank You ...!
prachippp is offline   Reply With Quote
Old 03-19-2012, 02:03 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by prachippp View Post
i want to restrict refresh option for online examination can any one give me solution as early as possible .....please
You can't. If the user presses F5 the page will refresh. You should use server-side coding to stop the timer resetting.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 03-20-2012, 01:20 AM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,461
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
replace
Code:
var timeCounter = $("b[id=show-time]").html();
with
Code:
var timeCounter = localStorage.dt || $("b[id=show-time]").html();



and
Code:
$("b[id=show-time]").html(updateTime);

with
Code:
$("b[id=show-time]").html(localStorage.dt=updateTime);



to reset the clock, somehow call:
Code:
localStorage.dt="";




OT:
Quote:
eval(1);
lol
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 03-20-2012 at 01:25 AM..
rnd me is offline   Reply With Quote
Old 03-20-2012, 01:59 AM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Note that not all browsers that people currently use support localStorage - it would be safer at the moment to use a cookie instead.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Old 03-20-2012, 08:28 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by felgall View Post
Note that not all browsers that people currently use support localStorage - it would be safer at the moment to use a cookie instead.
But the user can delete the cookie! That is hardly secure for an examination.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 03-20-2012, 08:34 AM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Philip M View Post
But the user can delete the cookie! That is hardly secure for an examination.
The user can turn off JavaScript completely as well if they want to. There is no client side solution that is all that secure.

Any decent security would have to be built using a server side script. and even that would need to use a session cookie to track the person - and the person could potentially delete that cookie just as they could if the cookie was set using JavaScript. The only difference would be that all the cookie would contain is a session id and everything else would be saved on the server using the session id to identify the person.

The only way around them being able to delete the cookie is to fail anyone who deletes the cookie.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 03-20-2012 at 08:36 AM..
felgall is online now   Reply With Quote
Old 03-20-2012, 09:04 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by felgall View Post
The user can turn off JavaScript completely as well if they want to. There is no client side solution that is all that secure.

Any decent security would have to be built using a server side script. and even that would need to use a session cookie to track the person - and the person could potentially delete that cookie just as they could if the cookie was set using JavaScript. The only difference would be that all the cookie would contain is a session id and everything else would be saved on the server using the session id to identify the person.

The only way around them being able to delete the cookie is to fail anyone who deletes the cookie.
How will you know that they have deleted the cookie? A new cookie and new session id will be generated.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 03-20-2012, 09:42 AM   PM User | #8
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
Quote:
Originally Posted by prachippp View Post
i want to restrict refresh option for online examination can any one give me solution as early as possible .....please
If this is for a real world application are you really, really sure you want to do this with javascript? The only totally secure way to do this without leaving the exam process vulnerable is to do it server side.

What do you want to stop from happening if the user refreshes the web page?
webdev1958 is offline   Reply With Quote
Old 03-20-2012, 01:50 PM   PM User | #9
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by webdev1958 View Post
If this is for a real world application are you really, really sure you want to do this with javascript? The only totally secure way to do this without leaving the exam process vulnerable is to do it server side.

What do you want to stop from happening if the user refreshes the web page?
See post#2. Re-starting the timer, of course.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 03-20-2012, 01:56 PM   PM User | #10
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
Quote:
Originally Posted by Philip M View Post
See post#2. Re-starting the timer, of course.
There are a lot more security issues to consider than just the timer

If the op replies to my question then maybe I'll be able to help more
webdev1958 is offline   Reply With Quote
Old 03-20-2012, 07:15 PM   PM User | #11
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Philip M View Post
How will you know that they have deleted the cookie? A new cookie and new session id will be generated.
You would then have two entries on the server with the same name attached - one for each of the cookies.

You just need it set up so that the server side data the cookie refers to doesn't get deleted until after the exam has been marked. Deleting the cookie would just remove the person's ability to complete that particular exam.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 11:34 PM.


Advertisement
Log in to turn off these ads.