JavaScript Datepicker issue in IE11 - crossobj.visibility=“hidden”;

穿精又带淫゛_ 提交于 2020-01-07 04:47:07

问题


Our Application is a dealer based application. This was implemented basically for IE8 browser, now since the dealers are upgrading to IE11, we are facing lot of issues (majorly in UI) in application. One among the issue is date picker.

When the user clicks on date picker in IE11 browser (compatible mode) the date picker popup shows whereas when the user clicks on date picker in IE11 browser (non compatible mode) there is no action performed. When I tried to debugged this using developer tools in IE browser, I found this error in console "SCRIPT5007: Unable to set property 'visibility' of undefined or null reference" which points to the piece of code "crossobj.visibility="hidden";" in function hideCalendar(). I have tried searching for any similar kind of issue in google, but I didn't find any so I am posting over here. Please look into the error and help me resolve this.

Please find below the full code of date picker:

<script>
var pathURL = '<%=request.getContextPath()%>';

    var fixedX = -1;                // x position (-1 if to appear below control)
    var fixedY = -1;                // y position (-1 if to appear below control)
    var startAt = 1;                    // 0 - sunday ; 1 - monday
    var showWeekNumber = 0;         // 0 - don't show; 1 - show
    var showToday = 0;              // 0 - don't show; 1 - show
    var imgDir = "/DIMSWEB/images/";    // directory for images ... e.g. var imgDir="/img/"

    var titlebar="#969798";
    var highlight="#FFCC99";

    var gotoString = "Go To Current Month";
    var todayString = "Today is";
    var weekString = "Wk";
    var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
    var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";
    var selectMonthMessage = "Click to select a month.";
    var selectYearMessage = "Click to select a year.";
    var selectDateMessage = "Select [date] as date."; // do not replace [date], it will be replaced by date.

    var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear;

    var bPageLoaded=false;
    var ie=document.all;
    var dom=document.getElementById;

    var ns4=document.layers;
    var today = new Date();
    var dateNow  = today.getDate();
    var monthNow = today.getMonth();
    var yearNow  = today.getFullYear();
    var imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif");
    var img = new Array();
    var bShow = false;
    var calVal;
 /* hides <select> and <applet> objects (for IE only) */
 function hideElement( elmID, overDiv )
 {
   if( ie )
   {
     for( i = 0; i < document.all.tags( elmID ).length; i++ )
     {
       obj = document.all.tags( elmID )[i];
       if( !obj || !obj.offsetParent )
       {
         continue;
       }

       // Find the element's offsetTop and offsetLeft relative to the BODY tag.
       objLeft   = obj.offsetLeft;
       objTop    = obj.offsetTop;
       objParent = obj.offsetParent;

       while( objParent.tagName.toUpperCase() != "BODY" )
       {
         objLeft  += objParent.offsetLeft;
         objTop   += objParent.offsetTop;
         objParent = objParent.offsetParent;
       }

       objHeight = obj.offsetHeight;
       objWidth = obj.offsetWidth;

       if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
       else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
       else if( overDiv.offsetTop >= ( objTop + objHeight ));
       else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
       else
       {
         obj.style.visibility = "hidden";
       }
     }
   }
 }

 /*
 * unhides <select> and <applet> objects (for IE only)
 */
 function showElement( elmID )
 {
   if( ie )
   {
     for( i = 0; i < document.all.tags( elmID ).length; i++ )
     {
       obj = document.all.tags( elmID )[i];

       if( !obj || !obj.offsetParent )
       {
         continue;
       }

       obj.style.visibility = "";
     }
   }
 }


    if (dom)
    {
        for (i=0;i<imgsrc.length;i++)
        {
            img[i] = new Image
            img[i].src = imgDir + imgsrc[i]

                                         ///alert(img[i].src);
        }
        //Modified By Subhadip:On 07thAugust,2006
        document.write ("<div onclick='bShow=true' id='calendar' style='z-index:+999;position:absolute;visibility:hidden;width:100px'><table bgcolor='#969798' style='font-family:arial;font-size:10px;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:10px}' bgcolor='#ffffff'><tr bgcolor='" + titlebar + "'><td><table><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><img src='"+imgDir+"close.gif' width='15' height='13' border='0' alt='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content1'></span></td></tr>")

        //Modified By Subhadip:On 07thAugust,2006   
        document.write ("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;width:65px'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;width:45px'></div>");
    }

    //var   monthName = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    var jan_key="<DimsBean:message key='january' langCode='${language}'></DimsBean:message>";
    var feb_key="<DimsBean:message key='february' langCode='${language}'></DimsBean:message>";
    var mar_key="<DimsBean:message key='march' langCode='${language}'></DimsBean:message>";
    var april_key="<DimsBean:message key='april' langCode='${language}'></DimsBean:message>";
    var may_key="<DimsBean:message key='may' langCode='${language}'></DimsBean:message>";
    var june_key="<DimsBean:message key='june' langCode='${language}'></DimsBean:message>";
    var july_key="<DimsBean:message key='july' langCode='${language}'></DimsBean:message>";
    var aug_key="<DimsBean:message key='august' langCode='${language}'></DimsBean:message>";
    var sep_key="<DimsBean:message key='september' langCode='${language}'></DimsBean:message>";
    var oct_key="<DimsBean:message key='october' langCode='${language}'></DimsBean:message>";
    var nov_key="<DimsBean:message key='november' langCode='${language}'></DimsBean:message>";
    var dec_key="<DimsBean:message key='december' langCode='${language}'></DimsBean:message>";


    var sun_key="<DimsBean:message key='sunday' langCode='${language}'></DimsBean:message>";
    var mon_key="<DimsBean:message key='monday' langCode='${language}'></DimsBean:message>";
    var tue_key="<DimsBean:message key='tuesday' langCode='${language}'></DimsBean:message>";
    var wed_key="<DimsBean:message key='wednesday' langCode='${language}'></DimsBean:message>";
    var thur_key="<DimsBean:message key='thursday' langCode='${language}'></DimsBean:message>";
    var fri_key="<DimsBean:message key='friday' langCode='${language}'></DimsBean:message>";
    var sat_key="<DimsBean:message key='saturday' langCode='${language}'></DimsBean:message>";


    var monthName = new Array(jan_key,feb_key,mar_key,april_key,may_key,june_key,july_key,aug_key,sep_key,oct_key,nov_key,dec_key);
    if (startAt==0)
    {
        dayName = new Array (sun_key,mon_key,tue_key,wed_key,thur_key,fri_key,sat_key)
    }
    else
    {
        dayName = new Array (mon_key,tue_key,wed_key,thur_key,fri_key,sat_key,sun_key)
    }
    var styleAnchor="text-decoration:none;color:black;"
    var styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;"

    function swapImage(srcImg, destImg){
        if (ie) { document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
    }

    function init() {
        if (!ns4)
        {
            if (!ie) { yearNow += 1900; }

            crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar;
            hideCalendar();

            crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth : document.selectMonth;

            crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear;

            monthConstructed=false;
            yearConstructed=false;

            sHTML1="<span id='spanLeft' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"white\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'    onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp;";
            sHTML1+="<span id='spanRight' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"white\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'    onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"right1.gif'   width=10 height=11 BORDER=0>&nbsp</span>&nbsp";
            sHTML1+="<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"white\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;";
            sHTML1+="<span id='spanYear' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"white\";window.status=\""+selectYearMessage+"\"'   onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"'  onclick='popUpYear()'></span>&nbsp;";

            document.getElementById("caption").innerHTML  = sHTML1;

            bPageLoaded=true;
        }
    }

    function hideCalendar() {
        crossobj.visibility="hidden";
        if (crossMonthObj != null){crossMonthObj.visibility="hidden";}
        if (crossYearObj != null){crossYearObj.visibility="hidden";}

        showElement( 'SELECT' );
        showElement( 'APPLET' );
    }

    function padZero(num) {
        return (num < 10)? '0' + num : num ;
    }

    function constructDate(d,m,y)
    {
        sTmp = dateFormat
        sTmp = sTmp.replace ("dd","<e>")
        sTmp = sTmp.replace ("d","<d>")
        sTmp = sTmp.replace ("<e>",padZero(d))
        sTmp = sTmp.replace ("<d>",d)
        sTmp = sTmp.replace ("mmm","<o>")
        sTmp = sTmp.replace ("mm","<n>")
        sTmp = sTmp.replace ("m","<m>")
        sTmp = sTmp.replace ("<m>",m+1)
        sTmp = sTmp.replace ("<n>",padZero(m+1))
        sTmp = sTmp.replace ("<o>",monthName[m])
        sTmp = sTmp.replace ("yyyy",y)
        sTmp = sTmp.replace ("yy",y.toString().substr(2,2))
        return sTmp
    }

    function closeCalendar() {
        var sTmp

        hideCalendar();
        //ctlToPlaceValue.value =   constructDate(dateSelected,monthSelected,yearSelected.toString().substr(2,2))
        ctlToPlaceValue.value = constructDate(dateSelected,monthSelected,yearSelected.toString())
        calVal=ctlToPlaceValue.value;
    }

    /*** Month Pulldown ***/

    function StartDecMonth()
    {
        intervalID1=setInterval("decMonth()",80)
    }

    function StartIncMonth()
    {
        intervalID1=setInterval("incMonth()",80)
    }

    function incMonth () {
        monthSelected++
        if (monthSelected>11) {
            monthSelected=0
            yearSelected++
        }
        constructCalendar()
    }

    function decMonth () {
        monthSelected--
        if (monthSelected<0) {
            monthSelected=11
            yearSelected--
        }
        constructCalendar()
    }

    function constructMonth() {
        popDownYear()
        if (!monthConstructed) {
            sHTML = ""
            for (i=0; i<12; i++) {
                sName = monthName[i];
                if (i==monthSelected){
                    sName = "<B>" + sName + "</B>"
                }
                sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"#dddddd\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
            }

            document.getElementById("selectMonth").innerHTML = "<table width=70 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='white' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'   onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" + sHTML + "</table>"

            monthConstructed=true
        }
    }

    function popUpMonth() {
        constructMonth()
        crossMonthObj.visibility = (dom||ie)? "visible" : "show"
        crossMonthObj.left = parseInt(crossobj.left) + 50
        crossMonthObj.top = parseInt(crossobj.top) + 26

        hideElement( 'SELECT', document.getElementById("selectMonth") );
        hideElement( 'APPLET', document.getElementById("selectMonth") );            
    }

    function popDownMonth() {
        crossMonthObj.visibility= "hidden"
    }

    /*** Year Pulldown ***/

    function incYear() {
        for (i=0; i<7; i++){
            newYear = (i+nStartingYear)+1
            if (newYear==yearSelected)
            { txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" }
            else
            { txtYear = "&nbsp;" + newYear + "&nbsp;" }
            document.getElementById("y"+i).innerHTML = txtYear
        }
        nStartingYear ++;
        bShow=true
    }

    function decYear() {
        for (i=0; i<7; i++){
            newYear = (i+nStartingYear)-1
            if (newYear==yearSelected)
            { txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" }
            else
            { txtYear = "&nbsp;" + newYear + "&nbsp;" }
            document.getElementById("y"+i).innerHTML = txtYear
        }
        nStartingYear --;
        bShow=true
    }

    function selectYear(nYear) {
        yearSelected=parseInt(nYear+nStartingYear);
        yearConstructed=false;
        constructCalendar();
        popDownYear();
    }

    function constructYear() {
        popDownMonth()
        sHTML = ""
        if (!yearConstructed) {

            sHTML = "<tr><td align='center' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'   onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"

            j = 0
            nStartingYear = yearSelected-3
            for (i=(yearSelected-3); i<=(yearSelected+3); i++) {
                sName = i;
                if (i==yearSelected){
                    sName = "<B>" + sName + "</B>"
                }

                sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#dddddd\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
                j ++;
            }

            sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'   onmouseup='clearInterval(intervalID2)'>+</td></tr>"

            document.getElementById("selectYear").innerHTML = "<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='white' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"   + sHTML + "</table>"

            yearConstructed = true
        }
    }

    function popDownYear() {
        clearInterval(intervalID1)
        clearTimeout(timeoutID1)
        clearInterval(intervalID2)
        clearTimeout(timeoutID2)
        crossYearObj.visibility= "hidden"
    }

    function popUpYear() {
        var leftOffset

        constructYear()
        crossYearObj.visibility = (dom||ie)? "visible" : "show"
        leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
        if (ie)
        {
            leftOffset += 6
        }
        crossYearObj.left = leftOffset
        crossYearObj.top = parseInt(crossobj.top) + 26
    }

    /*** calendar ***/

    function constructCalendar () {
        var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)

        var dateMessage
        var startDate = new Date (yearSelected,monthSelected,1)
        var endDate
        var colColour="bgcolor=white";
        var bSwitch;
        var nMax;

        if (monthSelected==1)
        {
            endDate = new Date (yearSelected,monthSelected+1,1);
            endDate = new Date (endDate - (24*60*60*1000));
            numDaysInMonth = endDate.getDate()
        }
        else
        {
            numDaysInMonth = aNumDays[monthSelected];
        }

        datePointer = 0
        dayPointer = startDate.getDay() - startAt

        if (dayPointer<0)
        {
            dayPointer = 6
        }

        sHTML = "<table  border=1 cellspacing=0 style='font-family:arial;font-size:10px;'><tr>"

//Set up row of Day Headings

        for (i=0; i<7; i++) {
            sHTML += "<td width='27' align='right' bgcolor='#dddddd'><B>"+ dayName[i].substr(0,3)+"</B></td>"
        }
        sHTML +="</tr><tr>"

//Fill in empty columns before start day
        for ( var i=1; i<=dayPointer;i++ )
        {
           if ((i%2))          
               sHTML += "<td bgcolor='white'>&nbsp;</td>"
           else    
               sHTML += "<td bgcolor='#dddddd'>&nbsp;</td>"
        }   
        if (dayPointer%2)
           bSwitch=false;
        else
           bSwitch=true;   

        for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
        {       
            dayPointer++;           

            if (bSwitch)
                 colColour=" bgcolor='white'";
            else
                 colColour=" bgcolor='#dddddd'";      

            sHTML += "<td align=right" + colColour +  ">"
            sStyle=styleAnchor
            if ((datePointer==odateSelected) && (monthSelected==omonthSelected) && (yearSelected==oyearSelected))
            { sStyle+=styleLightBorder }

            sHint = ""

            var regexp= /\"/g
            sHint=sHint.replace(regexp,"&quot;")

            dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "

            if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
            { sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();'><font color=#ff0000>&nbsp;" + datePointer + "</font>&nbsp;</a></b>"}
            else if (dayPointer % 7 == (startAt * -1)+1) //Sunday
            { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;<font color=#909090>" + datePointer + "</font>&nbsp;</a>" }
            else
            { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" }

            bSwitch=!bSwitch

            sHTML += ""
            if ((dayPointer+startAt) % 7 == startAt) { 
                bSwitch=true;
                sHTML += "</tr><tr>" 
            }
        }
//Add on as many empty cells as required to fill row        

        if (dayPointer > 35)
            nMax = 42;
        else
            nMax = 35;

        for ( var i=1; i<=(nMax-dayPointer);i++ )
        {
           if (bSwitch)        
               sHTML += "<td bgcolor='white'>&nbsp;</td>"
           else    
               sHTML += "<td bgcolor='#dddddd'>&nbsp;</td>"
            bSwitch=!bSwitch
        }   

        document.getElementById("content1").innerHTML   = sHTML
        document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[monthSelected] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG id='changeMonth' SRC='/DIMSWEB/images/drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
        document.getElementById("spanYear").innerHTML = "&nbsp;" + yearSelected + "&nbsp;<IMG id='changeYear' SRC='/DIMSWEB/images/drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
    }

    function popUpCalendar(ctl, ctl2, format) {
        var leftpos=0
        var toppos=0

        if (bPageLoaded)
        {

            if ( crossobj.visibility == "hidden" ) {
                ctlToPlaceValue = ctl2
                dateFormat=format;

                formatChar = " "
                aFormat = dateFormat.split(formatChar)
                if (aFormat.length<3)
                {
                    formatChar = "/"
                    aFormat = dateFormat.split(formatChar)
                    if (aFormat.length<3)
                    {
                        formatChar = "."
                        aFormat = dateFormat.split(formatChar)
                        if (aFormat.length<3)
                        {
                            formatChar = "-"
                            aFormat = dateFormat.split(formatChar)
                            if (aFormat.length<3)
                            {
                                // invalid date format
                                formatChar=""
                            }
                        }
                    }
                }


                tokensChanged = 0
                if ( formatChar != "" )
                {
                    // use user's date
                    aData = ctl2.value.split(formatChar)

                    for (i=0;i<3;i++)
                    {
                        if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
                        {
                            dateSelected = parseInt(aData[i], 10)
                            tokensChanged ++
                        }
                        else if ((aFormat[i]=="m") || (aFormat[i]=="mm"))
                        {
                            monthSelected = parseInt(aData[i], 10) - 1
                            tokensChanged ++
                        }
                        else if (aFormat[i]=="yyyy")
                        {
                            yearSelected = parseInt(aData[i], 10)
                            tokensChanged ++
                        }
                        else if (aFormat[i]=="yy")
                        {
                            if (aData[i]>50)
                            {
                               tempYear = parseInt(1900 + parseInt(aData[i]))
                            }
                            else
                            {
                               tempYear = parseInt(2000 + parseInt(aData[i]))
                            }
                            yearSelected = parseInt(tempYear, 10)
                            tokensChanged ++
                        }
                        else if (aFormat[i]=="mmm")
                        {
                            for (j=0; j<12; j++)
                            {
                                if (aData[i]==monthName[j])
                                {
                                    monthSelected=j
                                    tokensChanged ++
                                }
                            }
                        }                       
                    }
                }

                if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
                {
                    dateSelected = dateNow
                    monthSelected = monthNow
                    yearSelected = yearNow
                }

                odateSelected=dateSelected
                omonthSelected=monthSelected
                oyearSelected=yearSelected

                aTag = ctl
                do {
                    aTag = aTag.offsetParent;

                    if(aTag.offsetLeft>=600){
                        leftpos += (aTag.offsetLeft-200);
                    }
                    else{
                        leftpos += aTag.offsetLeft;
                    }

                    toppos += aTag.offsetTop;
                } while(aTag.tagName!="BODY");

                crossobj.left = fixedX==-1 ? ctl.offsetLeft + leftpos : fixedX
                crossobj.top = fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 : fixedY
                constructCalendar (1, monthSelected, yearSelected);
                crossobj.visibility=(dom||ie)? "visible" : "show"

                hideElement( 'SELECT', document.getElementById("calendar") );
                hideElement( 'APPLET', document.getElementById("calendar") );           

                bShow = true;
            }
            else
            {
                hideCalendar()
                if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format);}
            }
            ctlNow = ctl;
        }
        return calVal;
    }

    document.onkeypress = function hidecal1 () { 
        if (event.keyCode==27) 
        {
            hideCalendar();
        }
    }
    document.onclick = function hidecal2 () {       
        if (!bShow)
        {
            hideCalendar();
        }
        bShow = false
    }

    if(ie)  
    {
        init()
    }
    else
    {
        window.onload=init
    }

    function Navigate(obj,strURL,plsEnterUDate,noPastUDate,notValidYr){     
    var index = obj.getElementById("selLocationCode").selectedIndex;
    var selLocation = obj.getElementById("selLocationCode").options(index).value;
    var selCodeDesc = selLocation.split(",");
    obj.getElementById("hdLocationCode").value=selCodeDesc[0];

    obj.getElementById("hdLocationDesc").value=selCodeDesc[1];



    //frmLocUnavailAdd_onSubmit(obj);
        if(frmLocUnavailAdd_onSubmit(obj,plsEnterUDate,noPastUDate,notValidYr))
        {
            obj.frmLocUnavailAdd.action = strURL;
            obj.frmLocUnavailAdd.submit();        
        }
    }

    function Navigate1(obj,strURL,plsEnterUDate,noPastUDate,notValidYr){

    //frmLocUnavailAdd_onSubmit(obj);
    if(frmLocUnavailAdd_onSubmit(obj,plsEnterUDate,noPastUDate,notValidYr))
        {
          obj.frmLocUnavailAdd.action = strURL;
          obj.frmLocUnavailAdd.submit();          
        }
    }

</script>

Please note, 1. I cannot ask the dealer to turn on compatibility mode and start using the application I need a code fix to resolve the issue. 2. I also tried using DocType tag to resolve but that didn't help. 3. I have removed few functions at the end to character length restriction.

Thanks in advance for your help.


回答1:


The problem is that you have IE-specific code in there where you are setting crossobj.

crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar;

In the above line of code, it checks a variable called ie to determine whether the browser is IE, and if so, it runs different code to other browsers.

The problem for you with this code is that IE11 is much more standards-compliant than older IE versions, and thus doesn't need this kind of code at all.

(in fact, even IE8 shouldn't need it in this case; it's clearly aimed at much older versions than that. And I note that you also have browser checks for ns4 in there, which immediately tells me that your original script is very old code)

My advice is to consider replacing this whole code with a more modern and up-to-date calendar control. There are plenty available which will work in all current browsers and should be easy to plug into your site.

If you absolutely must keep the existing code, then the quick and dirty fix is to find the place where it sets the ie variable, and change the browser detection so it only detects IE8 and earlier (or whatever versions work with it, so that IE11 isn't detected as IE and thus acts as a 'normal' browser. This will probably fix the issue at hand, but may have other unintended consequences, so I'd suggest you're better off going through the code and ripping out all the browser detection stuff. My guess is that most of it is entirely unnecessary even for IE8. There may be some rewriting to be done as a result of that, but it's probably not a bad thing given the age of the code.

If you do find yourself needing some browser-specific code, consider using a tool like Modernizr that will detect support for a given feature rather than direct browser detection.

Hope that helps.



来源:https://stackoverflow.com/questions/24434491/javascript-datepicker-issue-in-ie11-crossobj-visibility-hidden

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!