Answer the question
In order to leave comments, you need to log in
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
})
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question