Open fancybox popup with iframe from a function
Asked Answered
T

2

6

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.

Teflon answered 25/1, 2013 at 12:26 Comment(0)
E
3

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.

Exhilarate answered 25/1, 2013 at 14:37 Comment(0)
M
2

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
    });
}
Mcgean answered 29/1, 2016 at 7:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.