Is there a video that is not connected to DOM autorun?

Here are three scenarios:

  • document.adoptNode,
  • document.importNode and
  • document.createElement + assign details.

In each case, the video starts automatically even if it is not connected to the DOM. This is incompatible with the behavior of an element <script>that will not be eval / download until it is attached to the DOM.

Should auto play video?

https://gist.run/?id=cb657718c3b6b34c043b34f3356d5a84

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>GistRun</title>
</head>
<body>
  <template>
    <video src="http://video.webmfiles.org/big-buck-bunny_trailer.webm"
           loop controls autoplay>
    </video>
  </template>
  <script>
    let template = document.querySelector('template');

    // SCENARIO 1: (causes autoplay)
    document.adoptNode(template.content);

    // SCENARIO 2: (causes autoplay)
//    document.importNode(template.content, true);

    // SCENARIO 3: (causes autoplay)
//    let video = document.createElement('video');
//    video.autoplay = 'autoplay';
//    video.controls = 'controls';
//    video.loop = 'loop';
//    video.src = 'http://video.webmfiles.org/big-buck-bunny_trailer.webm';
  </script>
</body>
</html>
+4
source share
1 answer

This is a copy against the difference in cuts.

In acceptNode, you cut out what is already interpreted if you want, while in importNode you copy node (i.e., create a description of this other thing), and then use this description to implement it on the house itself.

, ? ; - , - . - , -, . ( ), , .

0

All Articles