A
A
Aleksandr2016-04-28 09:23:20
JavaScript
Aleksandr, 2016-04-28 09:23:20

How to open fancybox popup from popup?

Please tell me I don't understand at all.
There is such a js code that opens fancybox popup and loads ajax content into it.

open: function(e) {
        var view = this
        e.preventDefault()
        var self = $(e.currentTarget)
        var src = self.attr('data-open')
        var href = self.href
        if (src.substr(0, 1) === '#') {
            $.fancybox($(src).html(), {
                type: 'html'
            });
        } else {
            $.fancybox.showLoading()
            $.ajax({
                type: 'get',
                url: src,
                data: {
                    'ajax': '1'
                }
            })
                .done(function(data) {
                    var data = $(data)
                    $(data).find('form').bind('submit', function(e) {
                        view.submitAjax(e)
                    })
                    $.fancybox(data)
                    $('.fancyboxHide').click(function(event) {
                        $.fancybox.close();
                    });
                })
                .fail(function() {
                    $.fancybox.hideLoading()
                    alert('("' + src + '") окно не доступно,\nбудет выполнена переадресация')
                    window.location.href = href
                })
        }
    }

In the content that it loads, there is a button that, when clicked, should open another popup.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Chekalin, 2016-04-28
@Sashjkeee

After inserting the content that came with the ajax request in fancybox, you should bind the click event to the new button and execute what you want in the handler. Fancybox has beforeShow events, in it you will need to find the node of the button, which will already be inserted from the content.

.done(function(data) {
  // ...
  $.fancybox(data, {
    beforeShow: function () {
      var $btn = // тут вы смотрите в this и там найдете свойство в виде jquery выборки в котором будет ваш контент

      $btn.on('click', function () {
        // ваши действия
      })
    }
  })
  // ...
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question