简体   繁体   中英

dart2js compiled code running in an unsupported browser

What happens if I try to run my generated javascript code in an unsupported browser? Like IE6?

I don't want to end up in a situation that my users will see a partly working broken app. Is there a way how to ensure that the dart/javascript will run only if the browser is supported and have my app degrade gracefully to some html banner "use a newer browser please" if it is not?

您始终可以在纯JavaScript中检测浏览器,并且在确保浏览器有效之前不要运行dart程序。

You could use the browser detector script here: http://www.quirksmode.org/js/detect.html

I wrote this code from the top of my head, I don't have a testing machine at my disposal right now:

var isNewFirefox = BrowserDetect.browser === 'Firefox'  && BrowserDetect.version >= 7;
var isNewChrome  = BrowserDetect.browser === 'Chrome';
var isNewIE      = BrowserDetect.browser === 'Explorer' && BrowserDetect.version >= 9;
var isNewSafari  = BrowserDetect.browser === 'Safari'   && BrowserDetect.version >= 5.1;
var isNewOpera   = BrowserDetect.browser === 'Opera'    && BrowserDetect.version >= 12;

if (isNewFirefox || isNewChrome || isNewIE || isNewSafari || isNewOpera) {
    var script = document.createElement('script');

    if (navigator.webkitStartDart || navigator.startDart || navigator.mozStartDart || navigator.oStartDart || navigator.msStartDart) {
        // Load Dart code!
        script.setAttribute('type', 'application/dart');
        script.setAttribute('src', 'http://.../foo.dart');
    } else {
        // Load dart2js code!
        script.setAttribute('src', 'http://.../foo.js');
    }

    document.body.appendChild(script);
} else {
    alert('Application wont work');
}

The version information can be found on: http://www.dartlang.org/support/faq.html#what-browsers-supported

Dart VM detection: http://www.dartlang.org/dartium/#detect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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