1

I want to display a modal window using fancybox at webpage load. This window will display a web page that will allow to choose the desired language. The page displayed in the popup window will be a web page (index_popup.php) located in the same folder as the home page (index.php).

halfer
  • 19,824
  • 17
  • 99
  • 186
donguyzo
  • 79
  • 2
  • 3
  • 4
  • 2
    possible duplicate of [How to launch jQuery Fancybox on page load?](http://stackoverflow.com/questions/807271/how-to-launch-jquery-fancybox-on-page-load) – Rory McCrossan Dec 08 '11 at 16:17

7 Answers7

11
window.jQuery(document).ready(function() {
    $.fancybox.open('#popup_box');
});
Reni Raj N R
  • 123
  • 2
  • 7
4

For fancybox 2: the documentation offers the following example: http://jsfiddle.net/STgGM/, to which I've added a document ready:

jQuery(document).ready(function($) {
    $.fancybox.open([
        {
            href : 'http://fancyapps.com/fancybox/demo/1_b.jpg',
            title : '1st title'
        },
        {
            href : 'http://fancyapps.com/fancybox/demo/2_b.jpg',
            title : '2nd title'
        }    
    ], {
        padding : 0   
    });
});
ptim
  • 14,902
  • 10
  • 83
  • 103
3

See Fancybox popup once time for session

<script type="text/javascript" src="/js/jquery/jquery.cookie.js"></script>
<script type="text/javascript">

(function($) {

    function openFancybox() {
        // launches fancybox after half second when called
        setTimeout(function () {
                $.fancybox.open(
                    [
                        {
                            href : 'http://fancyapps.com/fancybox/demo/1_b.jpg',
                        }    
                    ]
                );
        }, 1500);
    };

    var visited = $.cookie('visited'); // create the cookie
    if (visited == 'yes') {
        return false; // second page load, cookie is active so do nothing
    } else {
        openFancybox(); // first page load, launch fancybox
    };
    // assign cookie's value and expiration time
    $.cookie('visited', 'yes', {
        expires: 1 // the number of days the cookie will be effective
    });

})(jQuery);
</script>
Community
  • 1
  • 1
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
2
$(document).ready(function() {
    $('#popup_box').fancybox().trigger('click'); 
});

source

parisssss
  • 803
  • 16
  • 36
1
 <head>   
<script type="text/javascript">

    function autoClick() { 
    document.getElementById('onload').click();
    } 

    </script>
</head>

<body onLoad="autoClick();">

<a class="fancybox-media" id="onload" href="https://www.youtube.com/watch?v=MWydLB0nFew"></a>
Alin Razvan
  • 1,451
  • 13
  • 18
1

I tried the first solution:

window.jQuery(document).ready(function() {
    $.fancybox.open('#popup_box');
});

But I wasn't able to get it to load correctly, so I added a variable, then passed that in. It works exactly as I needed it to. Has the slider now, instead of loading each image separately.

This was my change:

window.jQuery(document).ready(function() {
    var box = $('#popup_box');
    $.fancybox.open(box);
});
Ambie
  • 11
  • 2
  • This doen't add any value to the question.If you think previously provided answer has a problem, you are always welcome to comment or flag it. If you think you had to modify a statement of previously given answer then try giving explanation around it why it solved the problem – Amit Phaltankar Aug 22 '18 at 23:17
1

Although FancyBox doesn't support a way to auto launch, there have been a few workarounds that seem pretty successful. One notable method I've used is in the link below to a similar question. This should accomplish the onPageLoad:

How to launch jQuery Fancybox on page load?

Community
  • 1
  • 1
king14nyr
  • 715
  • 6
  • 21