我目前正在爲圍繞HTML5視頻標籤的瀏覽器撰寫功能測試。我正在使用Typescript(JavaScript的一個版本)。我的團隊中有人問了一個很好的問題:功能測試(我寫的基於Dan Stringer的this great article)是否確實有效?撰寫功能測試,HTML5視頻標籤
是否需要設置video
標記的src
屬性以使功能失敗?或者,它只是試圖將video
標記添加到DOM(我所做的)?
export function DoesBrowserSupportHTML5VideoAndFileType(fileType : string) {
var mimeType = "video/" + fileType,
videoElement = document.createElement("video");
if (typeof videoElement.canPlayType === "function") {
// ... Do some mime-type evaluations
// and return accordingly
}
return false; // default
}
顯而易見,目前這並沒有被try-catch
聲明包圍;但是,我是否需要設置源屬性?
你現在的方式似乎是[Modernizr是如何做到的](https://github.com/Modernizr/Modernizr/blob/f839e2579da2c6331eaad922ae5cd691aac7ab62/feature-detects/video.js#L47),所以我想認爲你會好起來的。你有嘗試過嗎? –
@AndrewMyers謝謝你的鏈接!之前沒有看過那個項目。 – Thomas