如果用户空闲或没有活动,asp.net刷新页面

时间:2014-10-16 20:46:12

标签: javascript c# jquery asp.net settimeout

我使用了来自How to automatically reload a page after a given period of inactivity的代码到我的一个项目并且它有效,但现在我把它放在我当前的项目中它不起作用,我不知道为什么,它们是不同的项目,但在一天结束时它们只是2个webform aspx页面????

这假设每分钟刷新页面,除非有人按下某个键或移动鼠标。

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

控制台出错:

Uncaught ReferenceError: $ is not defined 

=&GT; $(document.body).bind(&#34; mousemove keypress&#34;,function(e){

我在aspx页面上使用的引用:

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

有没有可行的解决方案?我对JS或JQuery没有任何了解,但如果你告诉我它是如何工作的,我可以将它应用到我的程序中(笑)

2 个答案:

答案 0 :(得分:1)

$ not defined意味着你没有包含JQuery JavaScript库。添加类似的东西 在您的脚本之前<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>它应该可以正常工作

答案 1 :(得分:0)

在使用该代码之前,

必须在顶部包含JQuery库!