简体   繁体   中英

Open fancybox popup with iframe from a function

I have searched enough in the Stackoverflow and i could not able to 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 href value when i click the "openVideo" function not in the anchor tag itself.

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

Please suggest on this.

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

Need to add an ID to the anchor:

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

The 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 hard coded in your example, I did the same here. They can be variables if they need be -- just set them the same way.

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
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM