0

I used this code from: How to automatically reload a page after a given period of inactivity to one of my project and it worked, but now I put it in my current project it this doesn't work, I don't know why, they are different projects but at the end of the day they are just 2 webform aspx pages????

This supposes to refresh the page every minute unless someone presses a key or moves the mouse.

    <script>
     var time = new Date().getTime();
     $(document.body).bind("mousemove keypress", function(e) {
         time = new Date().getTime();
     });

     function refresh() {
         if(new Date().getTime() - time >= 60000) 
             window.location.reload(true);
         else 
             setTimeout(refresh, 10000);
     }

     setTimeout(refresh, 10000);
</script>

Error on console:

Uncaught ReferenceError: $ is not defined 

=> $(document.body).bind("mousemove keypress", function (e) {

References I used on the aspx page:

    <!-- Global styles START -->
<link href="/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Global styles END -->

<!-- Page level plugin styles START -->
<link href="/assets/global/plugins/fancybox/source/jquery.fancybox.css" rel="stylesheet">
<link href="/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
<!-- Page level plugin styles END -->

<!-- Theme styles START -->
<link href="/assets/global/css/components.css" rel="stylesheet">
<link href="/assets/global/css/plugins.css" rel="stylesheet">
<link href="/assets/frontend/layout/css/style.css" rel="stylesheet">
<link href="/assets/frontend/layout/css/style-responsive.css" rel="stylesheet">
<link href="/assets/frontend/layout/css/themes/blue.css" rel="stylesheet">
<link href="/assets/frontend/layout/css/custom.css" rel="stylesheet">
<!-- Theme styles END -->

//My body code here

 <!-- Load javascripts at bottom, this will reduce page load time -->
<!-- BEGIN CORE PLUGINS (REQUIRED FOR ALL PAGES) -->
<!--[if lt IE 9]>
<script src="/assets/global/plugins/respond.min.js"></script>
<![endif]-->
<script src="/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="/assets/global/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/assets/frontend/layout/scripts/back-to-top.js" type="text/javascript"></script>
<!-- END CORE PLUGINS -->

<!-- BEGIN PAGE LEVEL JAVASCRIPTS (REQUIRED ONLY FOR CURRENT PAGE) -->
<script src="/assets/global/plugins/fancybox/source/jquery.fancybox.pack.js" type="text/javascript"></script>
<!-- pop up -->
<script src="/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>

<script src="/assets/frontend/layout/scripts/layout.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        Layout.init();
        Layout.initUniform();
        //Layout.initTwitter();
    });
</script>
<!-- END PAGE LEVEL JAVASCRIPTS -->

Is there any working solution? I have zero knowledge about JS or JQuery but if you show me how it works I can apply it to my program (lol)

Community
  • 1
  • 1
Ronaldinho Learn Coding
  • 13,254
  • 24
  • 83
  • 110

2 Answers2

1

$ not defined means you didn't include JQuery JavaScript library. Add something like
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> before your script and it should work

Steve
  • 11,696
  • 7
  • 43
  • 81
0

have to include JQuery library on top, before using that code!

Ronaldinho Learn Coding
  • 13,254
  • 24
  • 83
  • 110