Embed youtube video without youtube link

后端 未结 6 791
野趣味
野趣味 2021-02-09 21:08

as you know that when you Embed youtube video in your web page, it works fine , but if you click on any part of screen, youtube website will open in new window.

is there

6条回答
  •  终归单人心
    2021-02-09 21:39

    You can leverage the Youtube API with this script which will also allow you to specify specific timecode and display only a portion of the video.

    var n = "youtube"; var y = document.createElement('script'); y.type = "text/javascript"; y.src = "//www.youtube.com/iframe_api"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(y, s); var player; var p = document.getElementById(n); var st = p.getAttribute("startTime"); var et = p.getAttribute("endTime"); var vi = p.getAttribute("videoID"); var ph = p.getAttribute("height"); var pw = p.getAttribute("width"); function onYouTubeIframeAPIReady() { player = new YT.Player(n, { height: ph,width: pw,playerVars: { 'rel': 0, 'showinfo': 0, 'hidecontrols': 1 }, events: { 'onReady': lv } }) } function lv(e) { e.target.cueVideoById({ videoId: vi,startSeconds: st,endSeconds: et }) }

提交回复
热议问题