Kênh 360 Công Nghệ Kênh 360 Công Nghệ

Trang chủ - Thiết kế web - Lập trình Javascript - Tạo banner quảng cáo thay đổi theo thời gian

Tạo banner quảng cáo thay đổi theo thời gian

Lập trình Javascript tạo banner quảng cáo thay đổi theo thời gian định trước. Hình ảnh banner quảng cáo nên có cùng kích thước.

Liên kết ảnh URLs và Liên kết URLs sẽ được lưu vào từng mảng là adImagesadURLs.
The img element for the link should be initialized to the first image in the array.
The cycle is started off using the onload event on the body element.

Chèn đoạn mã javascript này vào vào thẻ <head></head>

<script type="text/javascript">
        if (document.images){
            adImages = new Array("img/game.jpg",
                        "img/gallery.png", "img/kenh360.gif");
            adURLs = new Array("kenh360.com",
                        "toanquyen.com", "sieuhostvn.com");
            thisAd = 0;
        }
        function cycleAds(){
            if (document.images){
                if (document.adBanner.complete){
                    if (++thisAd == adImages.length)                
                        thisAd = 0;
                    document.adBanner.src = adImages[thisAd];
                }
            }
            // change to next sponsor every 3 seconds
            setTimeout("cycleAds()", 3000);
        }
        function gotoAd(){
            document.location.href="http://" + adURLs[thisAd];
        }
    </script></head>
<body onload="cycleAds()">
<a href="javascript:gotoAd()">
<img src="/img/game.jpg" name="adBanner" class="img1" alt="Game 360" title="Bộ sưu tập link download và các tin tức nóng hổi về các games hot nhất!"/></a>
Nguồn w3cschool


Tin liên quan:
Tin mới hơn:
Tin cũ hơn:

Lần cập nhật cuối ( Thứ sáu, 24 Tháng 7 2009 18:07 )  

Kênh 360 công nghệ

  • Nổi bật
  • Tin mới
  • Game mới
  • PrestaShop Guide
  • PrestaShop

Có thể bạn quan tâm

Download nhiều nhất

11/12
Download PES 2011 - FIFA 11
693
18/12
binkw32 dll
175
18/12
TeamViewerQS
49
English French German Japanese Korean