简体   繁体   English

多个jquery或javascript和datepicker无法正常工作

[英]Multiple jquery or javascripts and datepicker not working

I am working on a web application in which I need multiple popups/warning message in multiple cases. 我正在一个Web应用程序上工作,在这种情况下,在多种情况下我需要多个弹出窗口/警告消息。 These are three scenario's in which I need warning messages or popups. 这是我需要警告消息或弹出窗口的三种情况。

  1. A pop-up should be displayed when a user navigates to a different tab inside the application 当用户导航到应用程序内的其他选项卡时,应该显示一个弹出窗口
  2. A pop-up should be displayed when a user closes the tab or the browser window 当用户关闭标签或浏览器窗口时,应该显示一个弹出窗口
  3. When a user navigates to some other tab in the browser or when the user minimizes the browser, a warning message will be shown at the nth minute and user will be automatically taken to the application tab with a popup confirming the session timeout 当用户导航到浏览器中的其他选项卡或最小化浏览器时,第n分钟将显示警告消息,并且将自动将用户带到应用程序选项卡,并弹出弹出窗口确认会话超时

I am using the below code to do all this 我正在使用下面的代码来做所有这一切

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="idle_timer.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>



<script language="JavaScript">
$.noConflict();
$(".header v, .drop v").click(function(){
       window.onbeforeunload = null;
       return confirm("Are you sure you want to leave this page?");
});

</script>

<script language="javascript" type="text/javascript">          
$.noConflict();
$(window).on('mouseover', (function () {
           window.onbeforeunload = null;
       }));
       $(window).on('mouseout', (function () {
           window.onbeforeunload = ConfirmLeave;
       }));
       function ConfirmLeave() {
           return "";
       }
       var prevKey="";
       $(document).keydown(function (e) {       
                     if(window.onbeforeunload != null)
                           {
           if (e.key=="F5") {
               window.onbeforeunload = ConfirmLeave;
           }
           else if (e.key.toUpperCase() == "W" &amp; prevKey == "CONTROL") {
              if(y!=1)
               window.onbeforeunload = ConfirmLeave;   
           }
           else if (e.key.toUpperCase() == "R" &amp; prevKey == "CONTROL") {
               window.onbeforeunload = ConfirmLeave;
           }
           else if (e.key.toUpperCase() == "F4" &amp; (prevKey == "ALT" || prevKey == "CONTROL")) {
               window.onbeforeunload = ConfirmLeave;
           }
           prevKey = e.key.toUpperCase();
                           }
       });</script>

<script>
$.noConflict();
var IDLE_TIMEOUT = 10; //seconds
var _localStorageKey = 'global_countdown_last_reset_timestamp';
var _idleSecondsTimer = null;
var _lastResetTimeStamp = (new Date()).getTime();
var _localStorage = null;
var url      = window.location.href;
AttachEvent(document, 'click', ResetTime);
AttachEvent(document, 'mousemove', ResetTime);
AttachEvent(document, 'keypress', ResetTime);
AttachEvent(window, 'load', ResetTime);

try {
    _localStorage = window.localStorage;
}
catch (ex) {
}

_idleSecondsTimer = window.setInterval(CheckIdleTime, 1000);

function GetLastResetTimeStamp() {
    var lastResetTimeStamp = 0;
    if (_localStorage) {
        lastResetTimeStamp = parseInt(_localStorage[_localStorageKey], 10);
        if (isNaN(lastResetTimeStamp) || lastResetTimeStamp &lt; 0)
            lastResetTimeStamp = (new Date()).getTime();
    } else {
        lastResetTimeStamp = _lastResetTimeStamp;
    }

    return lastResetTimeStamp;
}

function SetLastResetTimeStamp(timeStamp) {
    if (_localStorage) {
        _localStorage[_localStorageKey] = timeStamp;
    } else {
        _lastResetTimeStamp = timeStamp;
    }
}

function ResetTime() {
    SetLastResetTimeStamp((new Date()).getTime());
}

function AttachEvent(element, eventName, eventHandler) {
    if (element.addEventListener) {
        element.addEventListener(eventName, eventHandler, false);
        return true;
    } else if (element.attachEvent) {
        element.attachEvent('on' + eventName, eventHandler);
        return true;
    } else {
        //nothing to do, browser too old or non standard anyway
        return false;
    }
}

function WriteProgress(msg) {
    var oPanel = document.getElementById("SecondsUntilExpire");
    if (oPanel)
         oPanel.innerHTML = msg;
    else if (console)
        console.log(msg);
}

function CheckIdleTime() {
    var currentTimeStamp = (new Date()).getTime();
    var lastResetTimeStamp = GetLastResetTimeStamp();
    var secondsDiff = Math.floor((currentTimeStamp - lastResetTimeStamp) / 1000);
    if (secondsDiff &lt; 1) {
        ResetTime();
        secondsDiff = 0;
    }
    WriteProgress((IDLE_TIMEOUT - secondsDiff) + "");
    if (secondsDiff &gt; IDLE_TIMEOUT-6) {
//             window.clearInterval(_idleSecondsTimer);
        var r=alert("Your session expires in 5 minutes \nPlease click \'OK\' to extend your session");

        if (r==true)
              {document.location.href = window.location.href;}

        ResetTime();
        //document.location.href = "logout.html";
    }
}
</script>

All these pop=ups are working fine but the problem is that I am using datepicker.js on the same page and if I use these scripts, I am not able to use datepicker or datewidget. 所有这些pop = ups都工作正常,但问题是我在同一页面上使用datepicker.js,如果使用这些脚本,则无法使用datepicker或datewidget。 Earlier, the datepicker was behaving perfectly. 早些时候,日期选择器表现得很好。 I don't why these scripts are causing problem. 我不明白为什么这些脚本会引起问题。 Is there any other script I can use or any other datepicker which will work fine with these scripts? 我是否可以使用其他任何脚本或可以与这些脚本配合使用的其他日期选择器?

What i can see you don't have included a jquery ui library but another version of jquery library: 我所看到的是,您没有包括jQuery用户界面库,而是另一种版本的jQuery库:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
</script>

i guess you need this add libraries before your custom code: 我想您在自定义代码之前需要此添加库:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js">
</script>

<script src="idle_timer.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="idle_timer.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

can you try replacing the above code as below, 您可以尝试如下替换上面的代码吗?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="idle_timer.js" type="text/javascript"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM