如何在 Youtube 中停止使用 Javascript 的视频? [英] How can I stop a video with Javascript in Youtube?

查看:25
本文介绍了如何在 Youtube 中停止使用 Javascript 的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:这里, 我按了一些视频.

问题:我尝试在 Firebug 的控制台中通过 Javascript 停止视频:

Problem: I try to stop the video by Javascript in the console of Firebug:

player.stopVideo(playerid):Void   [1] [2]

问题:为什么上面的命令不起作用?

Question: Why does not the command above work?

[1] 来源部分player.stopVideo():虚"

[1] Source for the part "player.stopVideo():Void"

[2] 我用 Firebug 从源代码中查看了 playerid.

[2] I looked playerid with Firebug from the source.

推荐答案

您的视频正在请求启用 JSAPI,所以您非常接近!您所需要的只是对嵌入式播放器的有效引用.检查您的页面发现您正在使用playerid"的 HTML DOM 元素 ID 来识别您的播放器.

Your video is requesting w/ the JSAPI enabled, so you are very close! All you need is a valid reference to the embedded player. Inspecting your page revealed that you are using the HTML DOM element id of "playerid" to identify your player.

例子:

<embed id="playerid" width="100%" height="100%" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#000000" name="playerid" style="" src="http://www.youtube.com/apiplayerbeta?enablejsapi=1&playerapiid=normalplayer" type="application/x-shockwave-flash">

要获得对播放器的引用然后停止视频,请使用以下代码:

To obtain a reference to the player and then stop the video use the following code:

var myPlayer = document.getElementById('playerid');
myPlayer.stopVideo();

这篇关于如何在 Youtube 中停止使用 Javascript 的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆