Tạo banner ads quảng cáo hiển thị luân phiên trong blogger

Thông thường trên các vị trí hiển thị quảng cáo của blog như header,  sidebar bạn chỉ có thể đặt 1 banner quảng cáo. Tuy nhiên với sức mạnh của ngôn ngữ Script bạn có thể  tạo ra hiệu ứng chạy luân phiên các banner.
Xem Demo ở cuối trang blog: Ctcptam.blogspot.com


Để thực hiện thủ thuật này, bạn hãy dán đoạn code bên dưới vào trong một tiện ích HTML/Javascript đối với Blogger.

Code:
<script type="text/javascript">
// Banner Rotation Script by Bloggerism
var ban = new Array();
var link = new Array();
var index = 0;
ban[0] = new Image();
ban[0].src = "URL_banner_0";
link[0] = "URL_link_0";
ban[1] = new Image();
ban[1].src = "URL_banner_1";
link[1] = "URL_link_1";
ban[2] = new Image();
ban[2].src = "URL_banner_2";
link[2] = "URL_link_2";
index = Math.random() * (ban.length);
index = Math.floor(index);
function rotator()
{if (index == ban.length) index = 0;
if (document.images) {
document.images.rotation.src = ban[index].src;
}
else {
document.getElementById('rotation').src=ban[index].src;
}
index++;
setTimeout('rotator()',3000);
}
function go() {window.open(link[index-1]);}
</script>
<img id="rotation" style="cursor:pointer;" src="" onclick="go();"/>
<script type="text/javascript">rotator();</script>

Trong đoạn code trên bạn lần lượt thay thế URL_banner tương ứng với URL_link.

Chú ý số 3000 ám chỉ 3000 mili giây (tương đương 3 giây) chỉ khoảng cách giữa các lần chuyển banner. Bạn có thể điều chỉnh con số này tùy ý.

Chúc các bạn thành công!

0 Response to "Tạo banner ads quảng cáo hiển thị luân phiên trong blogger"

Post a Comment