Popup quảng cáo là một công cụ mạnh mẽ giúp tăng tương tác, thu hút người dùng, quảng bá sản phẩm, dịch vụ hoặc trang web khác. Dưới đây là bộ sưu tập code popup phổ biến, dễ áp dụng cho cả Blogger, HTML hoặc các nền tảng web thông thường.
1. ✅ Popup xuất hiện nhiều tab mỗi khi click chuột
Thực hiện:
Thay:
<body>
Bằng:
<body onclick='open_popup()'>
Thêm đoạn script:
<script type='text/javascript'>
function open_popup() {
window.open("https://webdy.vn");
window.open("https://webdy.vn");
window.open("https://webdy.vn");
}
</script>
📌 Mặc định là mở 3 tab. Có thể thêm/bớt bằng cách nhân thêm dòng window.open(...).
⚠️ Cảnh báo: Dễ gây khó chịu với người dùng, không nên lạm dụng.
2. 🪟 Popup-under hiện sau trình duyệt
Popup sẽ mở ra phía sau cửa sổ trình duyệt.
Code 1 (Đơn giản):
<script>
function popup() {
var url = "https://webdy.vn";
window.open(url);
var popWin = window.open(url, 'popWin');
popWin.blur();
window.focus();
}
popup();
</script>
Code 2 (Chỉ hiện 1 lần mỗi phiên):
<script>
var popunder="https://webdy.vn";
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1";
var once_per_session=1;
function get_cookie(Name){
var search = Name + "=";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
}
}
return "";
}
function loadpopunder(){
win2 = window.open(popunder, "", winfeatures);
win2.blur();
window.focus();
}
function loadornot(){
if (get_cookie('popunder') == ''){
loadpopunder();
document.cookie="popunder=yes";
}
}
once_per_session == 0 ? loadpopunder() : loadornot();
</script>
3. 🖱 Popup mở tab mới khi click vào vị trí bất kỳ
<script>
function Set_Cookie(name, value, expires, path, domain, secure) {
var today = new Date();
var expires_date = new Date(today.getTime() + (expires));
document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}
function Get_Cookie(name) {
var start = document.cookie.indexOf(name + "=");
var len = start + name.length + 1;
if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";", len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len, end));
}
function popunder() {
if (Get_Cookie('cucre') == null) {
Set_Cookie('cucre', 'cucre Popunder', '86400000', '/', '', '');
var url = "https://webdy.vn";
var pop = window.open(url, 'windowcucre');
pop.blur();
window.focus();
}
}
function addEvent(obj, eventName, func) {
if (obj.addEventListener) obj.addEventListener(eventName, func, true);
else if (obj.attachEvent) obj.attachEvent("on" + eventName, func);
else obj["on" + eventName] = func;
}
addEvent(window, "load", function () {
addEvent(document.body, "click", function () {
popunder();
});
});
</script>
4. 🪟 Popup nhỏ ở góc màn hình
<script>
function addEvent(obj,eventName,func){
if(obj.addEventListener) obj.addEventListener(eventName,func,true);
else if(obj.attachEvent) obj.attachEvent("on"+eventName,func);
else obj["on"+eventName]=func;
}
addEvent(window,"load",function(){
addEvent(document.body,"click",function(){
if(document.cookie.indexOf("pnpopup=popactive")==-1){
document.cookie='pnpopup=popactive';
var params='width=400,height=300,top=500,left=1000,resizable=no,scrollbars=yes,location=yes';
window.open("https://webdy.vn",'popup_ad',params).blur();
window.focus();
}
});
});
</script>
5. 👆 Popup khi click chuột lần đầu
Thay:
<body>
Thành:
<body onclick="vtlai_popup();">
Và thêm đoạn sau:
<script>
var sinhvienit=0;
function getCookie(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return decodeURIComponent(document.cookie.match(re)[0].split("=")[1]);
return "";
}
function setCookie(name,value,days){
var expireDate = new Date();
expireDate.setDate(expireDate.getDate()+days);
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString();
}
function vtlai_popup(){
if(getCookie('popup_shown')=='') {
if(sinhvienit==0){
sinhvienit=1;
setCookie('popup_shown','true',1);
var urllist = ['https://webdy.vn','https://webdy.vn','https://webdy.vn'];
var url = urllist[Math.floor(Math.random() * urllist.length)];
var params = 'width=400,height=300,top=0,left=0,scrollbars=yes';
window.open(url, 'popup_ads', params);
}
}
}
</script>
6. 🪟 Popup mở nhiều cửa sổ khi click lần đầu
Tương tự như mục 5, nhưng mở nhiều tab:
function vtlai_popup(){
if(getCookie('popup_multi')=='') {
if(sinhvienit==0){
sinhvienit=1;
setCookie('popup_multi','true',1);
var urls = ['https://webdy.vn','https://webdy.vn','https://webdy.vn'];
for (var i = 0; i < urls.length; i++) {
window.open(urls[i], 'popup_' + i, 'width=500,height=400,top=100,left=100');
}
}
}
}
7. 📅 Popup 1 lần/ngày/1 IP
Thay <body> thành:
<body onclick='popunder();'>
Thêm:
<script>
function Set_Cookie(name, value, expires, path, domain, secure) {
var today = new Date();
var expires_date = new Date(today.getTime() + (expires));
document.cookie = name + "=" + escape(value) +
";expires=" + expires_date.toGMTString() +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}
function Get_Cookie(name) {
var start = document.cookie.indexOf(name + "=");
var len = start + name.length + 1;
if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";", len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len, end));
}
function popunder() {
if (Get_Cookie('cucre') == null) {
Set_Cookie('cucre', 'cucre Popunder', 86400000, '/', '', '');
var pop = window.open("https://webdy.vn", "windowcucre");
pop.blur();
window.focus();
}
}
window.onload = function(){
document.body.addEventListener("click", popunder);
};
</script>
✅ Tổng Kết
- Popup cần dùng đúng chỗ – đúng thời điểm – đúng cách để không gây phản cảm.
- Bạn có thể thay
"https://webdy.vn"bằng bất kỳ link sản phẩm, tiếp thị, landing page nào tùy ý.
Chào ! Bạn thấy nội dung này thế nào?





