Skip to content Skip to sidebar Skip to footer

Fancybox Iframe With Content Encoded In Js On Launch Page - How To Open On Page Load?

Thanks to this answer, I have a way of launching a fancybox iframe on page-load: http://www.casedasole.it/fancybox/A.html This answer shows how to open a fancybox iframe whose con

Solution 1:

Just do :

var myContent = "..."; // html as option "B"jQuery(document).ready(function ($) {
    $.fancybox({
        // API options as "B"// build the iframecontent: '<iframe id="myFrame" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" src="about:blank"></iframe>',
        afterShow: function () {
            var oIframe = document.getElementById('myFrame');
            var iframeDoc = (oIframe.contentWindow.document || oIframe.contentDocument);
            iframeDoc.open();
            iframeDoc.write(myContent);
            iframeDoc.close();
        }
    });
}); // ready

See JSFIDDLE

Notice the myContent variable contains the fullhtml structure, including DOCTYPE, <html>, <head> an <body> sections. Although it's not mandatory, it will give you more control over the settings of your initial (iframed) page.

Also notice in my jsfiddle I separated the base content (html basic structure) from the custom content (the <div> as in your example) for tidiness purposes ;)

Refs :

Post a Comment for "Fancybox Iframe With Content Encoded In Js On Launch Page - How To Open On Page Load?"