New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect browser compatibility #15657
Comments
Removed Type-Defect label. |
This might be a reasonable work-around: <script> In Dart: main() { Note: It is important that the above script tag is before the Dart script tag (unlike the snippet from Filip). Here is a complete HTML file: <!DOCTYPE html> |
This comment was originally written by @filiph That is brilliant, Peter, thank you! I still think, for the sake of developer experience, there should be at least some helper for this (or maybe it should be included in a wizard?). That's a lot of boilerplate for something that will be needed by a large portion of web apps. Also, I see you're using document.querySelector there, which afaik isn't supported by IE7-. (I know, that is fortunately a minority of browsers out there – but not a negligible part of the subset of browsers this code is for.) Wouldn't getElementById be safer? |
Filip, I think you're right about using getElementById, I was just confused because you had used ids that started with #. I think this code could be included in http://pub.dartlang.org/packages/browser, or its own package. |
Reassigning to library. cc @jmesserly. |
This issue was originally filed by @filiph
Feature request: I would like to have dart2js detect browser compatibility on runtime and in case the browser isn't up to the task of running the compiled code, a callback is called.
Maybe something like this (a total shot in the dark here):
<script type="text/javascript" src="compiled.js" data-incompatiblecallback="incompatibleAlert" defer></script>
<script>
var incompatibleAlert = function(e) {
// Show explanation. Hide UI.
document.getElementById('#incompatible').display = 'block';
document.getElementById('#ui').display = 'none';
}
</script>
This would be extremely useful out in the wild when I don't want users with incompatible browsers to stare blankly at a 'Loading' screen for long minutes before realizing that, in fact, the app won't load on their current browser at all.
Right now, my DIY alternative for this is to do this via CSS (a div is CSS-animated so it shows after some time, and hopefully, we load the Dart code to remove that div before that happens). But that's an ugly hack.
Maybe you have something more clever for this kind of situation up the sleeve already? Do tell!
The text was updated successfully, but these errors were encountered: