Jump to content

Loading Youtube video in Magnific pop up window


webdeveloper123
Go to solution Solved by gizmola,

Recommended Posts

Hi Guys,

I am a very basic Javascript programmer & don't really know Jquery and I need some help. I want to create a link (to a youtube video) which when clicked will open it in a new window. Now I found this page on codepen (https://codepen.io/kliedLABS/pen/DWZoww) and it seems to do exactly what I am looking for. Trouble is I am having problems implementing it. Here is my code:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Document </title>
<link rel="stylesheet" href="magnific-popup.css">

</head>
<body>
	<script src="jquery.magnific-popup.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script>
	
	$(document).ready(function() {
	$('.popup-youtube').magnificPopup({
    type: 'iframe'
  });
});

</script>

<div>
<a class="popup-youtube" href="https://www.youtube.com/watch?v=Euy4Yu6B3nU">Air</a>
</div>




</body>
</html>

Am I missing something obvious like I haven't called the function? This is a link to the the Magnific site: https://dimsemenov.com/plugins/magnific-popup/

Many thanks

Edited by webdeveloper123
Link to comment
Share on other sites

  • Solution

Yes you are missing something obviously different, which is that you are including jquery and the magnific popup code in the wrong order AND loading it in the body rather than the head section.  Try changing it to this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title> Document </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
    <script src="jquery.magnific-popup.js"></script>
    <link rel="stylesheet" href="magnific-popup.css">
    <script>
    $(document).ready(function() {
      $('.popup-youtube').magnificPopup({
        type: 'iframe'
      });
    });
    </script>
  </head>
  <body>
    <div>
      <a class="popup-youtube" href="https://www.youtube.com/watch?v=Euy4Yu6B3nU">Air</a>
    </div>
  </body>
</html>

 

Link to comment
Share on other sites

Hey gizmola,

Yes that's what was 90% of the problem. Thank you. The rest of the problem was that:

17 hours ago, gizmola said:
    <script src="jquery.magnific-popup.js"></script>

Didn't contain the iframe functions. So I just used the build tool to generate the JS file and only included iframe.

All done now

Thanks!

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.