ad.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var home_domain = "blog.csdn.net";
  2. var ad_cnt = ad_cnt || 0;
  3. /*CSDN广告延迟加载 t:广告类型,数字;id:容器id*/
  4. var Ad = function (t, id) {
  5. this.adType = t;
  6. this.containerId = id;
  7. this.adIndex = ad_cnt++;
  8. this.loadAd = function () {
  9. //document.domain = "csdn.net";
  10. var container = document.getElementById(this.containerId);
  11. var width = container.offsetWidth - 2 - container.style.paddingLeft - container.style.paddingRight;
  12. //var height = container.offsetHeight - 2 - container.style.paddingTop - container.style.paddingBottom;
  13. var frm = document.createElement('iframe');
  14. frm.id = "ad_frm_" + this.adIndex;
  15. frm.frameBorder = "0";
  16. frm.scrolling = "no";
  17. frm.style.borderWidth = "0px";
  18. frm.style.overflow = "hidden";
  19. if (width > 0) frm.style.width = width + "px";
  20. else frm.style.width = "98%";
  21. frm.style.height = "0px";
  22. frm.src = "http://" + home_domain + "/common/ad.html"
  23. + "?t=" + this.adType
  24. + "&containerId=" + this.containerId
  25. + "&frmId=" + frm.id;
  26. container.appendChild(frm);
  27. };
  28. if (jQuery) {
  29. jQuery((function (_ad) {
  30. return function () { _ad.loadAd(); }
  31. })(this));
  32. } else {
  33. this.loadAd();
  34. }
  35. };
  36. /*pongo广告延迟加载 id:广告id;continerId:容器id*/
  37. var PongoAd = function (id, continerId) {
  38. var func = 'window.showad' + id + '=function(html){document.getElementById("' + continerId + '").innerHTML=html;}';
  39. eval(func);
  40. function loadad(id) {
  41. var url = encodeURIComponent(top.location.href);
  42. var cbfun = "showad" + id;
  43. var src = 'http://a.pongo.cn/Job/GetAdForCallBack?id=' + id + '&UrlAdParam=' + encodeURIComponent(url) + '&CallBack=' + cbfun;
  44. var sc = document.createElement('script');
  45. sc.type = 'text/javascript';
  46. sc.async = true;
  47. sc.src = src;
  48. document.body.appendChild(sc);
  49. }
  50. setTimeout(function () { loadad(id); }, 1000);
  51. };