Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Is there any other option to attach event other than addEventListener, because attachevent has been removed from IE 11

$
0
0

I am trying to attach the event in IE 11 using addeventListner. but it returns 'undefined' but in case of up to ie 10, it find the support of attachEvent so it returns true.The piece of code is explained below:

window.onload = eval(function () {

             try {
                 var yourActiveXObject = document.getElementById('ftpControl');
                 if (typeof (yourActiveXObject) === 'undefined' || yourActiveXObject === null) {
                     alert('Unable to load ActiveX');
                     return;
                 }

                 // attach events
                 //  var status = yourActiveXObject.attachEvent('ProgressChange', ProgressChanged);
                 var status;

                 if (yourActiveXObject.attachEvent) {
                     status = yourActiveXObject.attachEvent('ProgressChange', ProgressChanged);
                     alert("attacheventlistner supported: status=" + status);                     
                 }
                 else if (yourActiveXObject.addEventListener) {
                    eval(status = yourActiveXObject.addEventListener('ProgressChange', ProgressChanged, true));
                    alert("addeventlistner supported: status=" + status);
                 }
                 else {
                     alert("None of the event supported: status= "+status);
                 }
             }
             catch (e) {
                 console.log("Exception occured: " +e.Message);
             }          

         });

This is the ProgressChanged method below:

                      

function ProgressChanged(progressPercentage, sender) {            
             if (progressPercentage == 0) {
                 if (blocked == false) {

                     $.unblockUI();
                     $.blockUI({ message: '<div id="newcustom" style="width:auto;  float:left; margin-right:10px; display:block"><span style="margin: 0 5px 0 5px; float:left"> <span class="left" style=" margin-top:16px; display:block">Compressing Please wait...' + '</span></span></div><input type="button" value="Cancel" onclick="onCancel()" id="btn" style="display: none; float:left; margin-top:12px;margin-right:5px;"/>' });
                     //   $('#custom').html('<span style="margin: 0 5px 0 5px; float:left"> <span class="left" style=" margin-top:16px; display:block;margin-right:10px;">Compressing...'+ ' %</span></span>');

                     blocked = true;
                 }
             }
             else {
                 if (progressPercentage != -1) {
                     $('#btn').show();
                     $('#newcustom').html('<span style="margin: 0 5px 0 5px; float:left"> <span class="left" style=" margin-top:16px; display:block;margin-right:10px;">Uploading...'+ progressPercentage + ' %</span></span>');
                 }
             }
        if(progressPercentage==100)
        {


            var planningId = document.getElementById('ftpControl').GetPlanningId();
            assignFileName();
            PageMethods.UploadCompleted(planningId, document.getElementById('MainContent_ftpPasswordHidden').value, document.getElementById('MainContent_patientNameHidden').value);
            UploadSucceeded();

             $.unblockUI();
             window.location.href = "DoctorHome.aspx";// + "?" + Date.parse(new Date());

        }
        if(progressPercentage==-1)
        {

            $.unblockUI();
        }
        if(progressPercentage==-99)
        {
          UploadFailed();
          $.unblockUI();
        }         
    }

The above code works fine up to IE10 but in IE11 it is unable to attach the event. Do we have any other option to make the code work in IE11? 


Viewing all articles
Browse latest Browse all 3527

Trending Articles