Open fancybox popup with iframe from function

I've searched enough on Stackoverflow and I couldn't find a thread to answer my question.

Below is my scenario,

function openVideo(videoid,urlid){
        var videourl = 'http://localhost/ptchoice-local/welcome/video/'+videoid+'/'+urlid;

        $("a#video_link").fancybox({
                    'type': 'iframe', 
            'width' : 1000,
            'height' : 600,
            'autoDimensions' : false,
            'autoScale' : false,
            'href' : videourl
        });

    $("a#video_link").trigger('click');
    return false;
} 

<a href="#" onclick="openVideo('2134sdf234532sdfs324234','1')">Show video</a>

      

So, I would like to set the href value when I click on the openVideo function not in the anchor tag itself.

Fancybox version: jquery.fancybox-1.3.4.pack.js

Please suggest this.

+3


source to share


2 answers


If I understood your question correctly, this should work for you:

You need to add an identifier to the anchor:

<a href="#" id="showVideo">Show video</a>

      



jQuery:

$("#showVideo").click(function () {
    var videourl = 'http://localhost/ptchoice-local/welcome/video/2134sdf234532sdfs324234/1';

    $("#video_link").fancybox({
        'type': 'iframe', 
        'width' : 1000,
        'height' : 600,
        'autoDimensions' : false,
        'autoScale' : false,
        'href' : videourl
    });

    $("#video_link").trigger('click');
});

      

Since the videoid and urlid were hardcoded in your example, I did the same here. They can be variables if needed - just set them the same.

+3


source


You can do it this way.



function openVideo(videoid,urlid) {
    var videourl = 'http://localhost/ptchoice-local/welcome/video/'+videoid+'/'+urlid;
    $.fancybox.open({
        href: videourl,
        type: 'iframe',
        padding: 0
    });
}

      

+1


source







All Articles