Rectangle 27 0

<a class="comparefancy" style="display:none;" href="#"></a>

but try firing fancybox manually like :

jQuery(document).ready(function () {
    var i = 0; // inside the click will be always 0 ... to be or not to be
    jQuery('.button').click(function () {
        var prdString = jQuery.map(jQuery(':checkbox:checked'), function (n, i) {
            return n.value;
        }).join(',');
        var url = '<?php echo Mage::getUrl(' catalog / product_compare / index ').' items / '; ?>' + prdString + '/uenc/';

        // open the corresponding URL in fancybox
        jQuery.fancybox(url, {
            // API options
            padding: 0 // example
        });

    });
});

I am just suggesting the fancybox part only (moved the i variable out of the click though). Make sure that you get the expected url value for each checked checkbox with the parameters passed throught the .map() method.

jquery fancybox iframe change the href value dynamically - Stack Overf...

jquery fancybox fancybox-2
Rectangle 27 0

Dont bind the fancybox function again and again, once is enough:

(function($) {
    $(function() { // short for $(document).ready();
        $('.button').click(function() {
            var i = 0,
                prdString = $.map($(':checkbox:checked'), function(n, i){
                    return n.value;
                }).join(','),
                url = '<?php echo Mage::getUrl('catalog/product_compare/index').'items/'; ?>'+ prdString + '/uenc/';

                $('.comparefancy').attr('href', url);
                setTimeout(function() {
                    $('.comparefancy').click();
                }, 50);
        });

        $('.comparefancy').fancybox({
            // optional settings
        });
    });
})(jQuery);

You are right, that wasn't fantastic of me but this didn't solve my problem, the second time I reselect checkboxes the fancybox won't load.

do you get an error or does simply nothing happen?

that's the problem, it doesn't say a thing. When it loads the first time I see all the get requests from the iframe, the second time it just ignores me (the url of the anchor link does change in the html though)

hm.. jQuery version? fancybox version? are you using the .click() or .trigger('click') handler? is the changed href url correct and valid?

well it's fancybox 2 and it's working as intended since the first time it fires fine. As you see in my code I use trigger click and the url is valid, it just adds different parameters. I'm not even getting the window with the "cannot load the content" message that you get when the url is wrong. JQuery is 1.7.1

jquery fancybox iframe change the href value dynamically - Stack Overf...

jquery fancybox fancybox-2
Rectangle 27 0

Dont bind the fancybox function again and again, once is enough:

(function($) {
    $(function() { // short for $(document).ready();
        $('.button').click(function() {
            var i = 0,
                prdString = $.map($(':checkbox:checked'), function(n, i){
                    return n.value;
                }).join(','),
                url = '<?php echo Mage::getUrl('catalog/product_compare/index').'items/'; ?>'+ prdString + '/uenc/';

                $('.comparefancy').attr('href', url);
                setTimeout(function() {
                    $('.comparefancy').click();
                }, 50);
        });

        $('.comparefancy').fancybox({
            // optional settings
        });
    });
})(jQuery);

You are right, that wasn't fantastic of me but this didn't solve my problem, the second time I reselect checkboxes the fancybox won't load.

do you get an error or does simply nothing happen?

that's the problem, it doesn't say a thing. When it loads the first time I see all the get requests from the iframe, the second time it just ignores me (the url of the anchor link does change in the html though)

hm.. jQuery version? fancybox version? are you using the .click() or .trigger('click') handler? is the changed href url correct and valid?

well it's fancybox 2 and it's working as intended since the first time it fires fine. As you see in my code I use trigger click and the url is valid, it just adds different parameters. I'm not even getting the window with the "cannot load the content" message that you get when the url is wrong. JQuery is 1.7.1

jquery fancybox iframe change the href value dynamically - Stack Overf...

jquery fancybox fancybox-2
Rectangle 27 0

Wow! i found it myself. The answer is changing it inside the beforeLoad callback.

$("#b_availSubmitButton").fancybox({
        beforeLoad : function() {
            this.href = $("#b_availFrm").prop("action")
            +'?aid='+$("input[name=aid]").val()
            +'&hotel_id='+$("input[name=hotel_id]").val()
            +'&lang='+$("input[name=lang]").val()
            +'&pb='+$("input[name=pb]").val()
            +'&stage='+$("input[name=stage]").val()
            +'&hostname='+$("input[name=hostname]").val()
            +'&checkin_monthday='+$("select[name=checkin_monthday]").val()
            +'&checkin_year_month='+$("select[name=checkin_year_month]").val()
            +'&checkout_monthday='+$("select[name=checkout_monthday]").val()
            +'&checkout_year_month='+$("select[name=checkout_year_month]").val()
            ;
        },
        'overlayColor'      : '#000',
        'width'             : '90%',
        'height'            : '90%',
        'autoScale'         : false,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'iframe'
});

works like a charm.

jquery fancybox iframe change the href - Stack Overflow

jquery iframe dynamic fancybox href
Rectangle 27 0

You could use .load() to insert the form in an existing (hidden) div and then display it in fancybox as inline content .... something like :

<a class="fancybox" href="external_form.html">display form</a>

<div id="formPlaceHolder" style="display: none"></div>
jQuery(document).ready(function ($) {
    $(".fancybox").on("click", function (e) {
        e.preventDefault();
        $('#formPlaceHolder').load("" + this.href + "", function () {
            $.fancybox(this, {
                // fancybox API options here
            }); 
        }); // load
    }); // on click
}); // ready

Eventually, you could use the afterClose callback to remove the form from the DOM after it has been submitted like :

afterClose: function(){
    $('#formPlaceHolder').empty();
}

jquery - How to load local href directly to fancybox without using ifr...

jquery fancybox overlay href fancybox-2
Rectangle 27 0

<a class="comparefancy" style="display:none;" href="#"></a>

but try firing fancybox manually like :

jQuery(document).ready(function () {
    var i = 0; // inside the click will be always 0 ... to be or not to be
    jQuery('.button').click(function () {
        var prdString = jQuery.map(jQuery(':checkbox:checked'), function (n, i) {
            return n.value;
        }).join(',');
        var url = '<?php echo Mage::getUrl(' catalog / product_compare / index ').' items / '; ?>' + prdString + '/uenc/';

        // open the corresponding URL in fancybox
        jQuery.fancybox(url, {
            // API options
            padding: 0 // example
        });

    });
});

I am just suggesting the fancybox part only (moved the i variable out of the click though). Make sure that you get the expected url value for each checked checkbox with the parameters passed throught the .map() method.

jquery fancybox iframe change the href value dynamically - Stack Overf...

jquery fancybox fancybox-2
Rectangle 27 0

No need to select all a tags and loop, you can do simply like

$(document).on('click', '.Images', function(e) {
    e.preventDefault();
    var Href = 'GetImg.php?img=' + $(this).attr("href");
    alert(Href);
    $.fancybox.open({
        href: Href,
        type: 'iframe',
        padding: 5
    });
});

Thanx that worked! now i need to workout how to re-size the iframe based on content.

jquery - Passing a dynamic href into Fancybox Iframe - Stack Overflow

jquery fancybox