简体   繁体   English

如何检查HTML5应用是否正常?

[英]How to check HTML5 app works or not?

I have a requirement where I can add both flash and embed HTML5 app on page. 我有一个要求,我可以在页面上添加Flash和嵌入HTML5应用。 But HTML5 app is not supported on many browsers. 但是,许多浏览器均不支持HTML5应用。 What I want to do is to check at runtime if the HTML5 app is not working fine, then show Flash File . 我想做的是在运行时检查HTML5应用程序是否运行正常,然后显示Flash File But I don't know how can I check at run time whether my app is displaying anything or not. 但是我不知道如何在运行时检查我的应用程序是否显示任何内容。 I have embedded the HTML5 code through following code in user-control: 我已经通过以下代码在用户控件中嵌入了HTML5代码:

<embed src='<fully qualified html5 app link>' height="<height>" width="<width>" />

The process of checking for supported functionality at runtime is often referred as "feature detection". 在运行时检查支持的功能的过程通常称为“功能检测”。 Modernizr is one popular JavaScript library that provides such "feature detects": http://modernizr.com/ Modernizr是一种流行的JavaScript库,提供了这种“功能检测”功能: http : //modernizr.com/

For example, let's start with the HTML you suggested, and add an id attribute for convenience: 例如,让我们从建议的HTML开始,并添加一个id属性以方便使用:

<embed id="fancy" height="<height>" width="<width>" />

If you wanted to use HTML5 Canvas, for example, but had to fall back to a Flash alternative in non-Canvas browsers, you could do something like this (in JavaScript, with Modernizr): 例如,如果您想使用HTML5 Canvas,但不得不在非Canvas浏览器中使用Flash替代品,则可以执行以下操作(在JavaScript中,使用Modernizr):

if (Modernizr.canvas) {
    // TODO: do whatever it is you want to do with Canvas
} else {
    // hook up your embed to the fallback Flash component
    document.getElementById('fancy').src = 'url/for/flash/component.swf';
}

HTML5 covers loads of functionality. HTML5涵盖了许多功能。 The precise "detect" required will vary based on your requirements, but Modernizr makes most of this quite simple. 所需的精确“检测”将根据您的要求而有所不同,但是Modernizr使大多数操作变得非常简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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