{"id":8391,"date":"2017-08-16T15:10:11","date_gmt":"2017-08-16T22:10:11","guid":{"rendered":"http:\/\/alannarisse.com\/blog\/?p=8391"},"modified":"2017-08-16T15:15:42","modified_gmt":"2017-08-16T22:15:42","slug":"stop-iframe-video-closing-modal","status":"publish","type":"post","link":"https:\/\/www.alannarisse.com\/blog\/stop-iframe-video-closing-modal\/","title":{"rendered":"How to stop an iframe video when closing modal"},"content":{"rendered":"<p>Needed to stop a video from playing and was impatient and having trouble getting it to work using <a href=\"https:\/\/developers.google.com\/youtube\/iframe_api_reference?csw=1#Playback_controls\">YouTubes APIs<\/a>. Found this solution and it worked right off the bat.<\/p>\n<p><a href=\"https:\/\/gomakethings.com\/stopping-youtube-vimeo-and-html5-videos-with-javascript\/\">https:\/\/gomakethings.com\/stopping-youtube-vimeo-and-html5-videos-with-javascript\/<\/a><\/p>\n<blockquote><p>Add this method to your script:<\/p>\n<pre>var stopVideo = function ( element ) {\r\nvar iframe = element.querySelector( 'iframe');\r\nvar video = element.querySelector( 'video' );\r\nif ( iframe !== null ) {\r\nvar iframeSrc = iframe.src;\r\niframe.src = iframeSrc;\r\n}\r\nif ( video !== null ) {\r\nvideo.pause();\r\n}\r\n};<\/pre>\n<p>Call the function as needed, passing the container element into the function:<\/p>\n<pre>stopVideo( tab );<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Needed to stop a video from playing and was impatient and having trouble getting it to work using YouTubes APIs. Found this solution and it worked right off the bat. https:\/\/gomakethings.com\/stopping-youtube-vimeo-and-html5-videos-with-javascript\/ Add this method to your script: var stopVideo = function ( element ) { var iframe = element.querySelector( &#8216;iframe&#8217;); var video = element.querySelector( &#8216;video&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-8391","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/posts\/8391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/comments?post=8391"}],"version-history":[{"count":2,"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/posts\/8391\/revisions"}],"predecessor-version":[{"id":8393,"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/posts\/8391\/revisions\/8393"}],"wp:attachment":[{"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/media?parent=8391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/categories?post=8391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.alannarisse.com\/blog\/wp-json\/wp\/v2\/tags?post=8391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}