Chào mọi người, hiện mình có đoạn code sau, tác dụng của nó là khi click vào 1 nút có đường link như https://devs.forumvi.com/post chẳng hạn
nó sẽ load page https://devs.forumvi.com/post dạng POPUP
Giờ mong mọi người có thể giúp mình sửa code dưới để nó có thể tự động load page ra class chỉ định mà không cần phải click nó mới load
Ví dụ: page https://devs.forumvi.com/post sẽ tự động được load và nằm ở class="noihienthipage" bên dưới cái nút span class="buttons" chứ không cần click vào nút buttons ms load page kia nữa
Hoặc nếu ai có code load page nào hay hơn, share mình vs nha!
- Code:
<span class="buttons"><a href="http://devs.forumvi.com/post">Go</a>
nó sẽ load page https://devs.forumvi.com/post dạng POPUP
Giờ mong mọi người có thể giúp mình sửa code dưới để nó có thể tự động load page ra class chỉ định mà không cần phải click nó mới load
Ví dụ: page https://devs.forumvi.com/post sẽ tự động được load và nằm ở class="noihienthipage" bên dưới cái nút span class="buttons" chứ không cần click vào nút buttons ms load page kia nữa
Hoặc nếu ai có code load page nào hay hơn, share mình vs nha!
- Code:
$(function() {
for (var a = document.getElementsByTagName('A'), i = 0, j = a.length, form; i < j; i++) {
if (/\/post|\/spa\//.test(a[i].href)) {
a[i].onclick = function() {
FA.Popup.open(this.href, this.innerHTML);
return false
}
}
}
});
(function() {
var version = 1;
if (!window.FA) window.FA = {};
if (FA.Popup) {
if (window.console) console.warn('FA.Popup has already been initialized.');
return
}
FA.Popup = {
lang: {
button_close: 'X',
default_title: 'Popup',
loading: 'Đang tải...'
},
active: false,
forum: {
version: version,
content: version ? '#main-content' : '#content-container > table > tbody > tr > td[width="100%"]',
pages: ['.gensmall:has(.sprite-arrow_subsilver_left, .sprite-arrow_subsilver_right) a[href^="/"], .nav:has(.sprite-arrow_subsilver_left, .sprite-arrow_subsilver_right) a[href^="/"]', '.pagination:not(strong) span a', '.paging a[href^="/"]', '.pagination a[href^="/"]'][version]
},
open: function(href, title, callback) {
if (FA.Popup.active) FA.Popup.close();
var box = document.createElement('DIV'),
overlay = document.createElement('DIV'),
content = document.createElement('DIV'),
close = document.createElement('INPUT');
close.type = 'button';
close.value = FA.Popup.lang.button_close;
close.className = 'fa_popup_button fa_popup_close';
close.onclick = FA.Popup.close;
content.id = 'fa_popup_content';
content.innerHTML = '<div class="fa_popup_loading">' + FA.Popup.lang.loading + '</div>';
overlay.id = 'fa_popup_overlay';
overlay.style.zIndex = '99998';
overlay.onclick = FA.Popup.close;
if (FA.Popup.forum.version == 2) box.className += ' pun';
box.id = 'fa_popup';
box.style.zIndex = '99999';
box.innerHTML = '<div class="fa_popup_title">' + (title ? title : FA.Popup.lang.default_title) + '</div>';
box.appendChild(close);
box.appendChild(content);
if (href) {
$.get(href, function(data) {
content.innerHTML = '';
if (callback) callback(data, content);
else {
var main = $(FA.Popup.forum.content, data)[0];
if (main) {
content.appendChild(main);
var page = $(FA.Popup.forum.pages, content);
if (page[0]) page.click(FA.Popup.getPage)
}
}
}).fail(function() {
content.innerHTML = '<div class="fa_popup_error">' + FA.Popup.lang.error_connection + '</div>'
})
} else if (callback) {
content.innerHTML = '';
callback(content)
}
document.body.style.overflow = 'hidden';
document.body.appendChild(overlay);
document.body.appendChild(box);
FA.Popup.active = true
},
close: function() {
var box = document.getElementById('fa_popup'),
overlay = document.getElementById('fa_popup_overlay');
box && document.body.removeChild(box);
overlay && document.body.removeChild(overlay);
document.body.style.overflow = '';
FA.Popup.active = false
},
getPage: function() {
var content = document.getElementById('fa_popup_content');
$.get(this.href, function(data) {
var main = $(FA.Popup.forum.content, data)[0],
page;
if (main) {
content.scrollTop = 0;
content.innerHTML = '';
content.appendChild(main);
page = $(FA.Popup.forum.pages, content);
if (page[0]) page.click(FA.Popup.getPage)
} else {
content.innerHTML = '<div class="fa_popup_error">' + FA.Popup.lang.error_getPage + '</div>'
}
}).fail(function() {
content.innerHTML = '<div class="fa_popup_error">' + FA.Popup.lang.error_connection + '</div>'
});
return false
}
}
})();