【问题标题】:How to pass current index to fancybox iframe如何将当前索引传递给fancybox iframe
【发布时间】:2012-06-12 21:39:06
【问题描述】:

我有一组链接,我调用了 fancybox 并启用了箭头,以便用户可以单击下一个和上一个。每个链接都装饰有 iframe 类和 href='/editdata.aspx'。我会删除箭头并传入当前索引,以便 editdata.aspx 保存按钮可以说“保存并下一步”,直到它到达最后一个链接,然后会说“保存并关闭”。

从editdata.aspx我使用

var numLinks = $(".link-items", parent.document.body).children("a.iframe").size();

这给了我链接的总数。我只需要知道正在向用户显示的当前链接,以便我可以更新保存按钮文本。

这是我在editdata.aspx中的代码示例:

// change the save button to save and next if fancybox is loading multiple links
        if (parent.$.fancybox) {
            var links = $(".links", parent.document.body);
            if (links && links.length > 0) {
                var numlinks  = $(links).children("a.popup").size();
                var index = getParameterByName('index');
                if (index == numlinks ) {
                    // this element is the last item to display so change the "save and next" to "save and close"
                    $("#btnSave").val("Save & Close");
                    $("#btnSave").click(function () {
                        parent.$.fancybox.close();
                    });
                }
                else {
                    $("#btnSave").val("Save & Next");
                    $("#btnSave").click(function () {
                        parent.$.fancybox.next();
                    });
                }
            }                
        }

function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }

我怎样才能做到这一点?

【问题讨论】:

    标签: iframe fancybox


    【解决方案1】:

    这对 v2 来说很容易 -

    jQuery(".fancybox").fancybox({
        beforeLoad : function() {
            this.href = this.href + '?index=' + this.index;
        }
    });
    

    【讨论】:

    • 这似乎对我不起作用。 this.index 的值始终是相同的数字。所有的 href 都有相同的索引值。
    • 我更新了我的问题以包含我在 iframe 页面中使用的 jquery。
    • 这绝对对我有用。顺便说一句,您可以在 iframe 中获取索引,例如 - parent.$.fancybox.current.index
    • (如果要预加载 iframe,则使用 parent.$.fancybox.coming.index)
    • 是的,你是对的。我的代码中还有其他导致问题的地方。当我创建一个简单的测试页面时,索引正在正确加载。
    猜你喜欢
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 2016-12-02
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    相关资源
    最近更新 更多