##// END OF EJS Templates
Backport PR #13147: Reword the YouTubeVideo autoplay WN
Blazej Michalik -
Show More
@@ -1,37 +1,39 b''
1 Enable to add extra attributes to iframe
1 ``YouTubeVideo`` autoplay and the ability to add extra attributes to ``IFrame``
2 ========================================
2 ===============================================================================
3
3
4 You can add any extra attributes to the ``<iframe>`` tag
4 You can add any extra attributes to the ``<iframe>`` tag using the new
5 since the argument ``extras`` has been added to the ``IFrame`` class.
5 ``extras`` argument in the ``IFrame`` class. For example::
6 for example::
7
6
8 In [1]: from IPython.display import IFrame
7 In [1]: from IPython.display import IFrame
9
8
10 In [2]: print(IFrame(src="src", width=300, height=300, extras=["hello", "world"])._repr_html_())
9 In [2]: IFrame(src="src", width=300, height=300, extras=['loading="eager"'])
11
10
12 <iframe
11 The above cells will result in the following HTML code being displayed in a
13 width="300"
12 notebook::
14 height="300"
15 src="src"
16 frameborder="0"
17 allowfullscreen
18 hello world
19 ></iframe>
20
13
21 Using it, you can autoplay ``YouTubeVideo`` by adding ``'allow="autoplay"'``,
14 <iframe
22 even in browsers that disable it by default, such as Google Chrome.
15 width="300"
23 And, you can write it more briefly by using the argument ``allow_autoplay``.
16 height="300"
17 src="src"
18 frameborder="0"
19 allowfullscreen
20 loading="eager"
21 ></iframe>
22
23 Related to the above, the ``YouTubeVideo`` class now takes an
24 ``allow_autoplay`` flag, which sets up the iframe of the embedded YouTube video
25 such that it allows autoplay.
26
27 .. note::
28 Whether this works depends on whether the autoplay policy of the browser
29 rendering the HTML allows it. It might not work in every circumstance, and
30 could get blocked by browser extensions.
31
32 Try it out!
24 ::
33 ::
25
34
26 In [1]: from IPython.display import YouTubeVideo
35 In [1]: from IPython.display import YouTubeVideo
27
36
28 In [2]: print(YouTubeVideo("video-id", allow_autoplay=True)._repr_html_())
37 In [2]: YouTubeVideo("dQw4w9WgXcQ", allow_autoplay=True)
29
38
30 <iframe
39 🙃
31 width="400"
32 height="300"
33 src="https://www.youtube.com/embed/video-id?autoplay=1"
34 frameborder="0"
35 allowfullscreen
36 allow="autoplay"
37 ></iframe>
General Comments 0
You need to be logged in to leave comments. Login now