user7610
user7610

Reputation: 28811

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?

Upvotes: 1

Views: 714

Answers (2)

Kai Sellgren
Kai Sellgren

Reputation: 30212

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

Upvotes: 2

tomaszkubacki
tomaszkubacki

Reputation: 3262

You can always detect browser in pure javascript and do not run dart program till you make sure browser is valid.

Upvotes: 2

Related Questions