[Summary] web work code sorting (continually updated)

File, blob

File download failed to convert Blob object to Json, handle exception error?

Use FileReader, the core code:

var reader = new FileReader()
reader.onload = e => console.log(JSON.parse(e.target.result))
reader.readAsText(blob)

Catch exceptions:

/ * * Capture Interface Error stream data export file 
 * @param {String} res interface has returned to normal information: the stream file error: error 
 * * / 
function catchDonwnloadError (RES) { 
  the let Result = {};
   return  new new Promise ((Resolve, Reject) => { 
      the let Reader = new new the FileReader (); 
      reader.onload = E => {
         the try {
                         // the JSON object returned by the backend processing string as JSON or 
                        IF ( typeof e.target.result === ' Object ' ) { 
                            Result = e.target.result; 
                        }
            Result = the JSON.parse (e.target.result); 
          } the finally {
             IF ( typeof ! result.status == 'undefined' ) {
                             // Element UI-component error 
              the this $ Message ({. 
                Message: result.message, 
                type: 'error' , 
                DURATION: . 5 * 1000 
              }); 
              Reject (); 
            } 
            Resolve (); 
          } 
      } 
            // returns stream file format used readAsText arraybuffer blob format readAsArrayBuffer
       reader.readAsText (res.data);
  })
}

Invocation:

 the this .donwnloadError (Result) .then (() => {
   // operation after successful export file 
  the this .Result = Result; 
})

Address issues: deal with file download failed, how to convert Blob object Json?

"Reference: FileReader"

Set secondary domain cookie sharing

That is, put the cookie domain is set to top-level domain.

function getdomain(){
    var domain = document.domain;
    var ip = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
    if(ip.test(domain)){
        return domain;
    }else{
        return document.domain.split('.').slice(1).join('.');
    }
}
var firstDomainName = getdomain();
document.cookie="userid=888abc;domain="+firstDomainName+";path=/";

other

Get IE browser version

function IEVersion () {
       var userAgent = the navigator.userAgent; // made browser userAgent string 
    var isIE = useragent.indexOf ( "compatible")> -1 && useragent.indexOf ( "MSIE")> -1; // determining whether IE <11 browser 
    var IsEdge = useragent.indexOf ( "Edge")> -1 && isIE;! // is determined whether the IE browser Edge 
    var isIE11 = useragent.indexOf ( 'Trident')> -1 && the userAgent .indexOf ( "RV: 11.0")> -1 ;
     IF (isIE) { 
        userAgent.match ( / MSIE (\ + D \ \ + D); /. G);
         var fIEVersion = parseFloat (the RegExp [ "$. 1" ]);
        if(fIEVersion == 7) {
            return 7;
        } else if(fIEVersion == 8) {
            return 8;
        } else if(fIEVersion == 9) {
            return 9;
        } else if(fIEVersion == 10) {
            return 10;
        } else {
            return 6;//IE版本<=7
        }
    } else if(isEdge) {
        return 'edge';//edge
    } The else  IF (isIE11) {
         return . 11; // IE11 of the 
    } the else {
         return -1; // not ie browser 
    } 
}

JS jump to the app download page in the app store

Go to App Store:

(https)|(itms-apps)://itunes.apple.com/app/id{appID}

Jump to Write a review:

(https)|(itms-apps)://itunes.apple.com/app/id{appID}?action=write-review

Jump to read reviews:

(https)|(itms-apps)://itunes.apple.com/app/viewContentsUserReviews?id={appID}

End mobile phones and pc side can be applied.

Sample code:

window.location.href = 'itms-apps://itunes.apple.com/app/id414478124?action=write-review'

 Analyzing or h5 JS Andrews ios device, to jump to the corresponding Download

com / app / id414478124 ' ; }, false
        ); } else if(isAndroid){ dom.addEventListener('touchstart', function (event) { window.location.href='http://www.XXX.com/apk/demo.apk'; },false); }else{ //PC 端 dom.addEventListener('click',function(){ //跳转到andriod下载地址 window.location.href='http://www.XXX.com/apk/demo.apk'; },false); } } })();

 

Guess you like

Origin www.cnblogs.com/moqiutao/p/11449010.html