/**
 * 
 */
/*判断浏览器是不是IE9*/
function isIE() {
    var myNav = navigator.userAgent.toLowerCase();
    console.log(myNav);
    return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1])<10 : false;
}

/*下载文件*/
function downloadFile(fileName, csvContent) {
  var D = document;
  var a = D.createElement('a');
  var strMimeType = 'application/octet-stream;charset=utf-8';
  var rawFile;

  if (!fileName) {
    var currentDate = new Date();
    fileName = "CWS Export - " + currentDate.getFullYear() + (currentDate.getMonth() + 1) +
                  currentDate.getDate() + currentDate.getHours() +
                  currentDate.getMinutes() + currentDate.getSeconds() + ".csv";
  }
  
  if (isIE()) {
    var frame = D.createElement('iframe');
    document.body.appendChild(frame);

    frame.contentWindow.document.open("text/html", "replace");
    frame.contentWindow.document.write('sep=,\r\n' + csvContent);
    frame.contentWindow.document.close();
    frame.contentWindow.focus();
    frame.contentWindow.document.execCommand('SaveAs', true, fileName);

    document.body.removeChild(frame);
    return true;
  }

  // IE10+
  if (navigator.msSaveBlob) {
    return navigator.msSaveBlob(new Blob(["\ufeff", csvContent], {
      type: strMimeType
    }), fileName);
  }

  //html5 A[download]
  if ('download' in a) {
    var blob = new Blob(["\ufeff"+csvContent], {
      type: strMimeType
    });
    rawFile = URL.createObjectURL(blob);
    a.setAttribute('download', fileName);
  } else {
    rawFile = 'data:attachment/plain,' + encodeURIComponent(csvContent);
    a.setAttribute('target', '_blank');
    a.setAttribute('download', fileName);
  }

  a.href = rawFile;
  a.setAttribute('style', 'display:none;');
  D.body.appendChild(a);
  setTimeout(function() {
    if (a.click) {
      a.click();
      // Workaround for Safari 5
    } else if (document.createEvent) {
    	var e = document.createEvent('MouseEvent');     
        e.initEvent('click', false, false);     
        a.dispatchEvent(e);
    }
    D.body.removeChild(a);
  }, 100);
}