##// END OF EJS Templates
Merge pull request #13148 from meeseeksmachine/auto-backport-of-pr-13147-on-7.x...
Blazej Michalik -
r26791:ad591789 merge
parent child Browse files
Show More
@@ -1,37 +1,38 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 the autoplay policy of the browser rendering
29 the HTML allowing it. It also could get blocked by some browser extensions.
30
31 Try it out!
24 ::
32 ::
25
33
26 In [1]: from IPython.display import YouTubeVideo
34 In [1]: from IPython.display import YouTubeVideo
27
35
28 In [2]: print(YouTubeVideo("video-id", allow_autoplay=True)._repr_html_())
36 In [2]: YouTubeVideo("dQw4w9WgXcQ", allow_autoplay=True)
29
37
30 <iframe
38 🙃
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