Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new HTML5 video element throught JavaScript

I am trying to create a new HTML5 video elemnt entirely throught JS. So I try to do it the same way I create a new image, like: obj = new Image() I write obj = new HTMLVideoElement(). However this doesn't work. I get the runtime error: Object doesn't support this action. What is wrong? Thanks.

like image 466
Light Avatar asked Jul 24 '12 08:07

Light


People also ask

How do you add a video in HTML5?

Use the <video> tag for inserting videos in HTML The <video> tag is added in HTML5 along with its sibling, <audio>. Before the release of HTML5, a video could only be played in a browser with a plug-in (like a flash). The HTML5 <video> element specifies a standard way to embed a video in a web page.

How do you add a video in HTML code?

HTML allows playing video in the web browser by using <video> tag. To embed the video in the webpage, we use src element for mentioning the file address and width and height attributes are used to define its size. Example: In this example, we are using <video> tag to add video into the web page.

What is the HTML 5 element for adding video to a web page?

The HTML <video> element is used to embed video in web documents. It may contain one or more video sources, represented using the src attribute or the source element. The <video> element is supported by all modern browsers.


1 Answers

The Image class is a special case.

The standard way to create any arbitrary HTML element is this:

var obj = document.createElement('video');
like image 70
Alnitak Avatar answered Oct 12 '22 16:10

Alnitak