百度联盟广告对接

  1. $(function () {
  2. var app = {
  3. config: {
  4. list: [
  5. {
  6. url: /www\.xxx\.com\/$/,
  7. desc: '首页导航下面广告位',
  8. dom: '#nav',
  9. area: 'after',
  10. newDom: '<div class="w1200" style=" text-align: center; margin: 10px auto;"></div>',
  11. script: '//aa.xxx.com/production/f_azcs/source/gp_p/z.js',
  12. }
  13. ]
  14. },
  15. run: function () {
  16. var list = this.config.list
  17. for (var i in list) {
  18. var page = list[i];
  19. if (page.url.test(location.href)) {
  20. if (page.items) {
  21. for (var j in page.items) {
  22. var item = page.items[j];
  23. this.doItem(item);
  24. }
  25. } else {
  26. this.doItem(page);
  27. }
  28. }
  29. }
  30. },
  31. doItem: function (item) {
  32. var next = (item.onBefore ? item.onBefore() : true);
  33. next = next && (item.isShow ? item.isShow() : true);
  34. if (next) {
  35. var newDom = $(item.newDom);
  36. if($(item.dom).length) {
  37. $(item.dom)[item.area](newDom);
  38. newDom[0].appendChild(this.createScript(item.script));
  39. }
  40. }
  41. },
  42. createScript: function (url) {
  43. var script = document.createElement('script');
  44. script.setAttribute('type', 'text/javascript');
  45. script.setAttribute('src', url);
  46. return script;
  47. }
  48. };
  49. app.run();
  50. });
文章不错, 赏你二两银子

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续努力!