Blog Tùng Hà

Code Popup hỏi trước khi thoát khỏi blog/web

Chào các bạn, mình lục lọi dữ lắm mới biết được code popup hỏi trước khi thoát khỏi trang web hoặc blogger. Đa phần ở các trang web khác, code không đầy đủ vì khi ở lại trang nó không điều hướng về trang khác.
Hôm nay mình xin chia sẻ code popup hỏi trước khi thoát khỏi web hoặc blogger và khi bấm ở lại trang nó sẽ chuyển về trang mà mình muốn.


affiliate_link


Code popup hỏi trước khi thoát khỏi web/blog

DEMO : XEM TẠI ĐÂY

Với cách này của Nguoichiase.com khi độc giả lỡ tay click chuột nhầm vào nút tắt thì cũng không thoát ra khỏi trang web của bạn nếu họ chưa xác nhận.



* Bắt đầu thủ thuật

1. Đăng nhập vào tài khoản Blogger
2. Vào phần Mẫu (Template)
3. Chọn chỉnh sửa HTML (Edit HTML)
4. Tìm thẻ </head> (Mẹo: Bấm chuột vào một vị trí bất kỳ trong ô chỉnh sửa HTML vào để sử dụng khung tìm kiếm nội tuyến như bài này.)
- Dán code bên dưới sau thẻ </head> vửa tìm được.

<script> var exittraffic_splashalertmessage = &quot;Chương trình dành một quà tặng trị giá 500.000 VND cho bạn ---&gt; Click Ở Lại để Đăng ký nhận quà tặng ngay !&quot;; </script>
<script type='text/javascript'>
//<![CDATA[
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

function DisableExitTraffic() {
PreventExitSplash = true;
}

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
function addClickEvent(a, i, func) {
if (typeof a[i].onclick != 'function') {
a[i].onclick = func;
}
}
theBody = document.body;
if (!theBody) {
theBody = document.getElementById("body");
if (!theBody) {
theBody = document.getElementsByTagName("body")[0];
}
}
var PreventExitSplash = false;
var LightwindowOpening = false;
function DisplayExitSplash() {

if (PreventExitSplash == false) {


window.scrollTo(0, 0);
if (is_firefox) {
//window.alert(exittraffic_splashalertmessage);
}
PreventExitSplash = true;
if (is_chrome||is_firefox) {
  timeout_variable = setTimeout("exittraffic_change_url();", 1000);
} else {
  document.location.href = "http://www.kiemtientreninternet.vn/p/ang-ky-khoa-hoc.html";
}

return exittraffic_splashalertmessage;
}
}
var a = document.getElementsByTagName('A');
for (var i = 0; i < a.length; i++) {
if (a[i].target !== '_blank') {
addClickEvent(a, i, function() {
PreventExitSplash = true;
});
}
else {
addClickEvent(a, i, function() {
PreventExitSplash = false;
});
}
}
disablelinksfunc = function() {
var a = document.getElementsByTagName('A');
for (var i = 0; i < a.length; i++) {
if (a[i].target !== '_blank') {
addClickEvent(a, i, function() {
PreventExitSplash = true;
});
}
else {
addClickEvent(a, i, function() {
PreventExitSplash = false;
});
}
}
}

addLoadEvent(disablelinksfunc);

disableformsfunc = function() {
// Makes that clicking on the links on the page will not cause this popup to appear
var f = document.getElementsByTagName('form');
for (var i = 0; i < f.length; i++) {
if (!f[i].onclick) {
f[i].onclick = function() {
if (LightwindowOpening == false) {
PreventExitSplash = true;
}
}
}
else if (!f[i].onsubmit) {
f[i].onsubmit = function() {
PreventExitSplash = true;
}
}
}
}

function exittraffic_change_url () {
disable_confirmation = false;
clearTimeout(timeout_variable); // just to make sure
document.location.href= "http://www.kiemtientreninternet.vn/p/ang-ky-khoa-hoc.html";
}

addLoadEvent(disableformsfunc);
window.onbeforeunload = DisplayExitSplash;
//]]>
</script>




- Các bạn thay nội dung ở phần chữ màu xanh trong đoạn code nha
- Các bạn thay đường link muốn chuyển tới khi người khác click ở lại trang này : Phần chữ màu đỏ trong đoạn code nha
- Lưu mẫu lại và xem kết quả nha.

Chúc các bạn thành công và luôn đồng hành cùng Người chia sẻ.
Xin chân thành cảm ơn


Thanh Tùng - Người chia sẻ

Thông kê truy cập

Quảng cáo

affiliate_link