return $r; } /** * @param int $page 页数 * @param int $pagesize 每页显示数量 * @return mixed */ function link_find($page = 1, $pagesize = 100) { $arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize); return $arr; } /** * @param $id * @return bool 返回FALSE失败 TRUE成功 */ function link_delete($id) { if (empty($id)) return FALSE; $r = link__delete(array('id' => $id)); link_delete_cache(); return $r; } //--------------------------kv + cache-------------------------- /** * @return mixed 返回全部友情链接 */ function link_get($page = 1, $pagesize = 100) { $g_link = website_get('friends_link'); if (empty($g_link)) { $g_link = link_find($page, $pagesize); $g_link AND website_set('friends_link', $g_link); } return $g_link; } // delete kv and cache function link_delete_cache() { website_set('friends_link', ''); return TRUE; } ?>javascript - Can you have a youtube video exit fullscreen on video complete - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can you have a youtube video exit fullscreen on video complete - Stack Overflow

programmeradmin4浏览0评论

For youtube videos you there is a button to exit fullscreen for both the Flash and HTML5 versions. Is there a way to programmatically exit fullscreen on video plete using Javascript? So basically once the video ends I want it to exit fullscreen mode.

For youtube videos you there is a button to exit fullscreen for both the Flash and HTML5 versions. Is there a way to programmatically exit fullscreen on video plete using Javascript? So basically once the video ends I want it to exit fullscreen mode.

Share Improve this question asked Feb 7, 2014 at 14:45 ski760ski760 1512 silver badges14 bronze badges 3
  • What library/framework will be used for embeding videos? Give us more details. I'd suggest MediaElement.js – Nicolae Olariu Commented Feb 7, 2014 at 14:52
  • I'm just using the youtube API. I'm not seeing a way to do this in the youtube api documentation. – ski760 Commented Feb 7, 2014 at 15:04
  • I think it's not possible for the moment as posted here. – Nicolae Olariu Commented Feb 7, 2014 at 15:14
Add a ment  | 

2 Answers 2

Reset to default 4

What you need is the following: document.exitFullscreen()

Here you can read more about the Fullscreen API

The short answer, is NO. At the moment, there is no way to programatically exit from Youtube player 100% safe, But there is a workaround that IS 100% safe.

Basically what you need to do is follow a series of simple steps and it will work fine in ALL browsers:

Step 1: Put your Youtube code inside an invisible DIV, lets say it is called "codeholder".

Step 2: Put a visible DIV as holder for the invisible DIV. This is where the code will go, let's say its called "ytPlayer".

Step 3: When the page loads, copy the invisible DIV into the visible DIV. This can be done for example as follows:

document.getElementById('ytPlayer').innerHTML = document.getElementById('codeholder').innerHTML;

Step 4: I'm assuming you are using the Youtube API, so, when the YouTube.PlayerState.ENDED event is fired (or whenever you want), copy the invisible DIV into the visible DIV. This will force the browser to close the player to close fullscreen and it will display the original player.

I like to do this on YouTube.PlayerState.ENDED event because this is a destructive way to close the player, so, the video will NOT continue playing after "exiting" full screen.

However, the Youtube API allows you to "read" the playing position, and you can restore the playing position easily with some light coding. There will be a pause of a fraction of a second though.

发布评论

评论列表(0)

  1. 暂无评论