Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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 ...!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,895
    Thanks
    202
    Thanked 2,530 Times in 2,508 Posts
    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.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    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:
    eval(1);
    lol
    Last edited by rnd me; 03-20-2012 at 01:25 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,895
    Thanks
    202
    Thanked 2,530 Times in 2,508 Posts
    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.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    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.
    Last edited by felgall; 03-20-2012 at 08:36 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,895
    Thanks
    202
    Thanked 2,530 Times in 2,508 Posts
    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.

  • #8
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    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?

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,895
    Thanks
    202
    Thanked 2,530 Times in 2,508 Posts
    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.

  • #10
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    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

  • #11
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •