本文实例讲述了php广告加载类的用法,非常实用。分享给大家供大家参考。具体方法如下:

该php广告加载类,支持异步与同步加载。需要使用Jquery实现。

ADLoader.class.php类文件如下:

<"text/javascript" src="/UploadFiles/2021-04-02/'.self::$_jsclass.'">
<"htmlcode">
/** 异步加载广告 
*  Date:  2013-08-04 
*  Author: fdipzone 
*  Ver:  1.0 
*/ 
var ADLoader = (function(){ 
 
  var _ads = [],   // 广告集合 
    _step = 300,  // 广告加载间隔 
    _async = true, // 是否异步加载 
    _loaded = 0;  // 已经加载的广告数 
   
  /** loadAd 循环加载广告 
  * @param int c 第几个广告 
  */ 
  function loadAD(c){ 
    if(_loaded>=_ads.length){ 
      return ; 
    } 
 
    if($('#'+_ads[c].domId).length>0){ // 判断dom是否存在 
 
      if(_async){ // 异步执行 
 
        crapLoader.loadScript(getScript(_ads[c]), _ads[c].domId, { 
          success: function(){ 
            completeAd(); 
          } 
        }); 
       
      }else{ // 将同步加载的广告显示 
 
        var ad_container = $('#'+_ads[c].domId+'_container'); 
        ad_container.find('embed').attr('wmode','transparent').end().find('object').each(function(k, v){ 
          v.wmode = 'transparent'; // 将flash变透明 
        }); 
        $('#'+_ads[c].domId)[0].appendChild(ad_container[0]); 
        ad_container.show(); 
         
        completeAd(); 
      } 
    }else{ // dom不存在 
      completeAd(); 
    } 
  } 
 
  /** 加载完广告后处理 */ 
  function completeAd(){ 
    _loaded ++; 
    setTimeout(function(){ 
      loadAD(_loaded); 
    }, _step);     
  } 
 
  /** 获取广告 
  * @param Array ad 广告参数 
  */ 
  function getScript(ad){ 
    var ret = null; 
 
    switch(ad.type){ 
      case 'openx': // openx code ad 
        ret = 'data:text/javascript;base64,' + ad.zoneId + 'dmFyIG0zX3UgPSAobG9jYXRpb24ucHJvdG9jb2w9PSdodHRwczonPydodHRwczovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpdmVyeS9hanMucGhwJzonaHR0cDovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpdmVyeS9hanMucGhwJyk7CnZhciBtM19yID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpKjk5OTk5OTk5OTk5KTsKaWYgKCFkb2N1bWVudC5NQVhfdXNlZCkgZG9jdW1lbnQuTUFYX3VzZWQgPSAnLCc7CmRvY3VtZW50LndyaXRlICgiPHNjciIrImlwdCB0eXBlPSd0ZXh0L2phdmFzY3JpcHQnIHNyYz0nIittM191KTsKZG9jdW1lbnQud3JpdGUgKCI/em9uZWlkPSIgKyB6b25laWQpOwpkb2N1bWVudC53cml0ZSAoJyZhbXA7Y2I9JyArIG0zX3IpOwppZiAoZG9jdW1lbnQuTUFYX3VzZWQgIT0gJywnKSBkb2N1bWVudC53cml0ZSAoIiZhbXA7ZXhjbHVkZT0iICsgZG9jdW1lbnQuTUFYX3VzZWQpOwpkb2N1bWVudC53cml0ZSAoZG9jdW1lbnQuY2hhcnNldCA/ICcmYW1wO2NoYXJzZXQ9Jytkb2N1bWVudC5jaGFyc2V0IDogKGRvY3VtZW50LmNoYXJhY3RlclNldCA/ICcmYW1wO2NoYXJzZXQ9Jytkb2N1bWVudC5jaGFyYWN0ZXJTZXQgOiAnJykpOwpkb2N1bWVudC53cml0ZSAoIiZhbXA7bG9jPSIgKyBlc2NhcGUod2luZG93LmxvY2F0aW9uKSk7CmlmIChkb2N1bWVudC5yZWZlcnJlcikgZG9jdW1lbnQud3JpdGUgKCImYW1wO3JlZmVyZXI9IiArIGVzY2FwZShkb2N1bWVudC5yZWZlcnJlcikpOwppZiAoZG9jdW1lbnQuY29udGV4dCkgZG9jdW1lbnQud3JpdGUgKCImY29udGV4dD0iICsgZXNjYXBlKGRvY3VtZW50LmNvbnRleHQpKTsKaWYgKGRvY3VtZW50Lm1tbV9mbykgZG9jdW1lbnQud3JpdGUgKCImYW1wO21tbV9mbz0xIik7CmRvY3VtZW50LndyaXRlICgiJz48XC9zY3IiKyJpcHQ+Iik7'; 
        break; 
       
      case 'url': // url ad 
        ret = ad.url; 
        break; 
    } 
    return ret; 
  } 
 
  /** 同步加载广告 
  * @param Array ad 广告参数 
  */ 
  function writeAd(ad){ 
    switch(ad.type){ 
      case 'openx': 
        var m3_u = (location.protocol=='https:'"<scr"+"ipt type='text/javascript' src='"+m3_u); 
        document.write ("" + ad.zoneId); 
        document.write ('&cb=' + m3_r); 
        if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); 
        document.write (document.charset "&loc=" + escape(window.location)); 
        if (document.referrer) document.write ("&referer=" + escape(document.referrer)); 
        if (document.context) document.write ("&context=" + escape(document.context)); 
        if (document.mmm_fo) document.write ("&mmm_fo=1"); 
        document.write ("'><\/scr"+"ipt>"); 
        break; 
       case 'url': 
        document.write ('<script type="text/javascript" src="/UploadFiles/2021-04-02/' + ad.url + '">

demo.php示例程序如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
 <head> 
 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
 <title> AD Loader </title> 
 <style type="text/css"> 
 .banner1{margin:10px; border:1px solid #CCCCCC; width:728px; height:90px;} 
 .banner2{margin:10px; border:1px solid #CCCCCC; width:300px; height:250px;} 
 </style> 
 <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.10.1.min.js">
<"<scr"+"ipt type='text/javascript' src='"+m3_u); 
document.write ("" + zoneid); 
document.write ('&cb=' + m3_r); 
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); 
document.write (document.charset "&loc=" + escape(window.location)); 
if (document.referrer) document.write ("&referer=" + escape(document.referrer)); 
if (document.context) document.write ("&context=" + escape(document.context)); 
if (document.mmm_fo) document.write ("&mmm_fo=1"); 
document.write ("'><\/scr"+"ipt>"); 
<"_blank" href="http://xiazai.jb51.net/201409/ADLoader(jb51.net).rar">本站下载。

希望本文所述对大家的php程序设计有所帮助。

标签:
php,广告,加载,类

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“php广告加载类用法实例”

暂无“php广告加载类用法实例”评论...