Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  148] [ 3]  / answers: 1 / hits: 92701  / 11 Years ago, tue, october 8, 2013, 12:00:00

Is it possible to dynamically create a HTML5 video element so that I can access the element by API's like document.getElementById or Name but it may not show up in the webpage.



Something like div.hide() or something in that direction ?


More From » ajax

 Answers
14

You can try



var video = document.createElement('video');

video.src = 'urlToVideo.ogg';
video.autoplay = true;


you can also use the canPlayType method to check if the browser supports the video format you want to use before setting source



if (video.canPlayType('video/ogg').length > 0) {
/* set some video source */
}


The method returns maybe or perhaps depending on browser. If empty string it means it can't play it.



You can now use the video using the API. Just store it globally. You can later insert it into the DOM. Hope this helps.


[#75142] Monday, October 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yosefleod

Total Points: 113
Total Questions: 100
Total Answers: 115

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;