Magnific-popup: Youtube embed video link

Created on 2 Sep 2015  路  8Comments  路  Source: dimsemenov/Magnific-Popup

Hi.
I try insert embed YT video link like "http://www.youtube.com/embed/uz8NDWopZyU" with iframe

$.magnificPopup.open({
                        items: {
                            src: video,
                            type:'iframe'
                        },
                    })

But YT return error.
In the html of iframe tag I'll see next link:

<iframe class="mfp-iframe" src="//www.youtube.com/embed/http://www.youtube.com/embed/uz8NDWopZyU?autoplay=1" frameborder="0" allowfullscreen=""></iframe>

In advance I don't know what the link is.

question

Most helpful comment

Late to the party, in case someone needs to use the actual embed URL for Magnific, here is my process:

  • Write a function that gets the input URL, checks it's format and then ensures that the /embed/ url is returned.
  • In Magnific markup always use the processed URL which is in the embed format.
  • Add the following patterns to magnific, to essentially use the input URL as the url without processing it further:
// Video popup, Backend enforces embed URL before it gets here.
    $('.js-popup-video').magnificPopup({
        type: 'iframe',
        iframe: {
            patterns: {
                youtube: {
                    index: 'youtube.com/',
                    id: function (url) { return url },
                    src: '%id%'
                },
                vimeo: {
                    index: 'vimeo.com/',
                    id: function (url) { return url },
                    src: '%id%'
                }
            }
        }
    });

All 8 comments

@snnwolf: Don't use embedded link (http://www.youtube.com/embed/uz8NDWopZyU), use direct link instead (https://www.youtube.com/watch?v=uz8NDWopZyU).

We have a website where the content editors have varying degrees of tech savvy-ness (so to speak). Most hit share to get the url or get the embed link, not using the embed link isn't a solution.

I saw a question about this and it was suggested that you could define your own link types, can you point me in the right direction please? I need to create a solution that supports all possible youtube link types (not the one they're least likely to use when inserting videos into the website).

Thanks

Ho about link to channel? (http://www.youtube.com/channel/UCYHWmCD-V7iNAKdU6yX4mOg/live)

Late to the party, in case someone needs to use the actual embed URL for Magnific, here is my process:

  • Write a function that gets the input URL, checks it's format and then ensures that the /embed/ url is returned.
  • In Magnific markup always use the processed URL which is in the embed format.
  • Add the following patterns to magnific, to essentially use the input URL as the url without processing it further:
// Video popup, Backend enforces embed URL before it gets here.
    $('.js-popup-video').magnificPopup({
        type: 'iframe',
        iframe: {
            patterns: {
                youtube: {
                    index: 'youtube.com/',
                    id: function (url) { return url },
                    src: '%id%'
                },
                vimeo: {
                    index: 'vimeo.com/',
                    id: function (url) { return url },
                    src: '%id%'
                }
            }
        }
    });

@WJakub thanks for the info! You're process fixed my problem

@WJakub It's been a while but thanks, I'll be sure to give this a go if we encounter this problem again

@WJakub Thanks Bro...Its working perfectly

This solution will work best for all YouTube link patterns.
https://stackoverflow.com/a/48696208

Was this page helpful?
0 / 5 - 0 ratings

Related issues

landitus picture landitus  路  3Comments

amir-rahnama picture amir-rahnama  路  4Comments

influxweb picture influxweb  路  4Comments

wojto picture wojto  路  4Comments

klihelp picture klihelp  路  4Comments