Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    133
    Thanks
    2
    Thanked 0 Times in 0 Posts

    What if this code appears twice on one page?

    Hello everyone!
    I know very little about javascript, and was wondering if someone could tell me if anything bad will happen from this code appearing twice on a page.
    The reason I ask, is because help files on the BuySellAds website says it should only appear once on a page, and must go immediately below the <body> tag. Whereas tech support says I can just place it right above the ad code, wherever it is on the page.

    So do you guys think having this code appear twice on a page will cause any types of problems?

    Code:
    <!-- BuySellAds Ad Code -->
    <script type="text/javascript">
    (function(){
      var bsa = document.createElement('script');
         bsa.type = 'text/javascript';
         bsa.async = true;
         bsa.src = 'http://s3.buysellads.com/ac/bsa.js';
      (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
    })();
    </script>
    <!-- End BuySellAds Ad Code -->
    So how it would look would be:
    Code:
    <!-- BuySellAds Ad Code -->
    <html>
    <body>
    <div class="content">
    <p>Example content</p>
    <div class="ad1">
    <script type="text/javascript">
    (function(){
      var bsa = document.createElement('script');
         bsa.type = 'text/javascript';
         bsa.async = true;
         bsa.src = 'http://s3.buysellads.com/ac/bsa.js';
      (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
    })();
    </script>
    <!-- End BuySellAds Ad Code -->
    <!-- BuySellAds Zone Code -->
    <div id="bsap_1" class="bsarocks bsap_e1"></div>
    <!-- End BuySellAds Zone Code -->
    </div>
    <p>More content</p>
    <div class="ad2">
    <!-- BuySellAds Ad Code -->
    <script type="text/javascript">
    (function(){
      var bsa = document.createElement('script');
         bsa.type = 'text/javascript';
         bsa.async = true;
         bsa.src = 'http://s3.buysellads.com/ac/bsa.js';
      (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
    })();
    </script>
    <!-- End BuySellAds Ad Code -->
    <!-- BuySellAds Zone Code -->
    <div id="bsap_2" class="bsarocks bsap_e2"></div>
    <!-- End BuySellAds Zone Code -->
    </div>
    </div>
    </body>
    </html>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    That would be adding the same script to the page immediately before the </body> tag twice. Just what effect running the script twice would have would depend on just exactly what is in that script. The best you can hope for is that the second time the script runs doesn't interfere with what happened the first time.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    133
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for the reply.
    I looked the script up and it seems to be this:

    Code:
    var _bsap={apiurl:'http:\/\/s3.buysellads.com\/r\/',dz:[],dii:[],inv:[],drop:function(a,b){this.dii[b]=this.dii[b]||0;var l='bsap_'+b+(++this.dii[b]===1?'':'_'+this.dii[b]);document.write('<div id="'+l+'" class="bsap_'+b+' bsap"><\/div>');this.idrop(l,a,b)},idrop:function(i,a,b){this.dz[b]=this.dz[b]||[];this.dz[b].push(i);if(!document.getElementById('_bsap_js_'+a)){var c=document.createElement('script'),d=new Date();d.setMinutes(0);d.setSeconds(0);d.setMilliseconds(0);c.type='text\/javascript';c.id='_bsap_js_'+a;c.src=this.apiurl+'s_'+a+'.js?v='+d.getTime();c.setAttribute('async','async');document.getElementsByTagName('head')[0].appendChild(c)}else if(this.jz)this.deploy()},exec:function(){this.callback=typeof(BSACallback)==='function'?BSACallback:function(){};for(var cl=function(cl){for(var n=!!document.getElementsByClassName,ret=[],els=n?document.getElementsByClassName(cl):document.getElementsByTagName('*'),p=n?false:new RegExp('(^|\\s)'+cl+'(\\s|$)'),i=0;i<els.length;i++)if(!p||p.test(els[i].className))ret.push(els[i]);return ret},bs=cl('bsarocks'),id,pk,p=/bsap_([a-f0-9]+)/i,i=0;i<bs.length&&(id=bs[i].getAttribute('id'))&&(rid=id.split('_')[1])&&(pk=bs[i].getAttribute('rel')||((pk=p.exec(bs[i].className))?pk[1]:''))&&(bs[i].className='bsap_'+rid+' bsap');i++)this.idrop(id,pk,rid)},deploy:function(){for(var zi=0,wi,z,a,b,db;zi<this.jz.length&&(z=this.jz[zi])&&(wi=1);zi++)while(++wi<10&&(db=this.dz[z.id])&&(a=db.pop())&&(b=document.getElementById(a)))(this.inv[z.id]=function(){new _bsap.zone(b,z,_bsap);return false})()},zone:function(b,z,bsa){bsa.filter(z.filterby,function(f){var zf=[],zs=z.filters,i,j;for(i=0;zs&&i<f.length;i++)zf=zf.concat(typeof zs[f[i].toLowerCase()]=='object'?zs[f[i].toLowerCase()].ads:[]);zf=!zf.length?(zs.all||z):{ads:zf};var empty=0,c=(!zf||!zf.ads||!zf.ads.length)?[]:bsa.getads(zf,z.nads),d,e=c[0],t='',o='',fr,a,backfilled=false,tf=z.format?z.format:(z.type&&z.type==1?2:0),ts=Math.round(+new Date()/1000),w=z.width,h=z.height,css=function(x){var newel=document.createElement('style');newel.type='text\/css';newel.id='bsa_css';var ie6=newel.styleSheet?typeof(newel.styleSheet.cssText)=='unknown':false,el=!ie6?document.getElementById('bsa_css')||newel:newel;el.styleSheet?(ie6?el.styleSheet.cssText=x:el.styleSheet.cssText+=x):el.appendChild(document.createTextNode(x));document.getElementsByTagName('head')[0].appendChild(el)};if(z.model==1&&zf&&zf.ads)for(empty=100,i=0;i<zf.ads.length;i++)empty-=zf.ads[i].per/z.nads;if(z.noempties&&z.noempties==1)empty=0;if(t<=1){var ah=(typeof(ShowAdHereBanner)==='object'?ShowAdHereBanner[z.id]:z.showadhere)>0,ra=(typeof(RepeatAll)==='object'?RepeatAll[z.id]:z.repeathere)>0}if(tf==0){if(typeof(ShowAdHereBanner)==='undefined'&&!z.nostyle){var bs=z.bannerstyles,sc='div.bsap_'+z.id+'{width:'+(z.vertical>0?w+'px':'100%')+';display:block}div.bsap_'+z.id+' a{width:'+w+'px}div.bsap_'+z.id+' a img{padding:0}div.bsap_'+z.id+' a em{font-style:normal}';for(i=0;i<bs.length;i++)sc+='div.bsap_'+z.id+' '+bs[i];if(w<100)sc+='div.bsap_'+z.id+' a em{display:block;text-indent:-9000px}div.bsap_'+z.id+' a{height:'+h+';line-height:0}div.bsap_'+z.id+' a.adhere{font-size:0}';sc+='div.bsap_'+z.id+' a{line-height:100%}div.bsap_'+z.id+' a.adhere{width:'+w+'px;height:'+h+'px;line-height:'+(h*8)+'%}html>body div.bsap_'+z.id+' a.adhere{width:'+(w-2)+'px;height:'+(h-2)+'px}div.bsap_'+z.id+' img.s{height:0;width:0}';if(z.model==1)sc+=w==728?('div.bsap_'+z.id+'{line-height:9px}div.bsap_'+z.id+' .bsap_adhere2,div.bsap_'+z.id+' iframe{float:left}div.bsap_'+z.id+' .bsap_adhere2 a{height:90px;width:20px;background:url(http:\/\/s3.buysellads.com\/ac\/ah20x90_1.gif) no-repeat 0 0;text-indent:-9999px}'):('div.bsap_'+z.id+'{line-height:9px}div.bsap_'+z.id+' .bsap_adhere a{height:19px;width:'+(w-2)+'px;font-size:10px;background:#f1f1f1;border:1px solid #e1e1e1;border-top:none;border-bottom-left-radius:4px;-moz-border-radius-bottomleft:4px;-webkit-border-bottom-left-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-bottomright:4px;-webkit-border-bottom-right-radius:4px;text-shadow:1px 1px 0 #fff;line-height:16px}.bsap_backfillframe{border:0}');css(sc)}for(i=0,j=0;i<c.length&&(a=bsa.getads(c[i],1)[0]);i++,(Math.random()*100<(z.model==1&&z.nads>c.length?(100-c[i-1].per):empty))||(j++,o+=(a.rawframe?('<iframe width="'+w+'" height="'+h+'" id="ad_'+a.id+'_frame" src="'+a.rawframe+'" frameborder="0" class="bsap_adframe" scrolling="no"><\/iframe>'):(a.flash&&bsa.hasFlash()?('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+z.width+'" height="'+z.height+'" id="bsa_flash"><param name="movie" value="'+a.flash+'"/><param name="menu" value="false"/><param name="quality" value="high"/><param name="wmode" value="opaque"/><param name="allowScriptAccess" value="always"/><param name="FlashVars" value="clickTag='+encodeURIComponent(bsa.tracker('click.go',a.id,z.id,'','','&link='+a.link.replace('[timestamp]',ts).replace(/&amp;/g,'&')))+'"/><embed src="'+a.flash+'" width="'+z.width+'" height="'+z.height+'" quality="high" wmode="opaque" menu="false" allowScriptAccess="always" swliveconnect="true" flashvars="clickTag='+encodeURIComponent(bsa.tracker('click.go',a.id,z.id,'','','&link='+a.link.replace('[timestamp]',ts).replace(/&amp;/g,'&')))+'" type="application/x-shockwave-flash"></embed></object>'):('<a '+bsa.link(a.id,z.id,a.link.replace('[timestamp]',ts))+' class="ad'+j+' '+(j%2===0?'even':'odd')+'" title="'+a.alt+'" id="bsa_'+a.id+'" target="_blank"><img src="'+a.img.replace('[timestamp]',ts)+'" width="'+z.width+'" height="'+z.height+'" alt="'+a.alt+'"\/><\/a>'))),t+=a.id+';')){}if(z.model==1&&z.cpmbackfill&&j==0){for(var r=Math.random(),bn=0;bn<z.cpmbackfill.length&&z.cpmbackfill[bn]&&z.cpmbackfill[bn][0]<r;r-=z.cpmbackfill[bn++][0]){}if(z.cpmbackfill[bn]&&z.cpmbackfill[bn][0]&&z.cpmbackfill[bn][1].length>0){o+='<iframe width="'+w+'" height="'+h+'" id="backfill_'+z.id+'_frame" src="'+z.cpmbackfill[bn][1]+'" frameborder="0" class="bsap_backfillframe" scrolling="no"><\/iframe>';backfilled=true}}for(i=j;!backfilled&&i<z.nads&&ah&&(i<(ra?z.nads:(j+1)));i++,o+=(bsa.callback(z.id,i-1,z.nads)||'<a href="http:\/\/buysellads.com\/buy\/detail\/'+z.siteid+'\/zone\/'+z.id+'?utm_source=site_'+z.siteid+'&utm_medium=website&utm_campaign=adhere&utm_content=zone_'+z.id+'" title="Advertise Here" class="adhere ad'+i+' '+(i%2===0?'even':'odd')+'" target="_blank">Advertise Here<\/a>')){}if(z.model==1&&ah&&(j==z.nads||backfilled))o+='<div class="bsap_adhere'+(w==728?'2':'')+'"><a href="http:\/\/buysellads.com\/buy\/detail\/'+z.siteid+'\/zone\/'+z.id+'?utm_source=site_'+z.siteid+'&utm_medium=website&utm_campaign=cpmadhere&utm_content=zone_'+z.id+'">advertise here<\/a><\/div>'}else if(tf==1){((z.model==1&&Math.random()*100*z.nads<(empty||0))||c.length==0)&&ah&&(c=[{id:-i,link:'http:\/\/buysellads.com\/buy\/detail\/'+z.siteid+'\/zone\/'+z.id,img:bsa.apiurl+'d\/adhere.png',alt:'Advertise Here',text:'Advertise in this spot with Online Advertising Marketplace'}]);this.bsaonecss||z.nostyle==1||css('.one{position:relative}.one .bsa_it_ad{display:block;padding:15px;border:1px solid #e1e1e1;background:#f9f9f9;font-family:helvetica,arial,sans-serif;line-height:100%;position:relative}.one .bsa_it_ad a{text-decoration:none}.one .bsa_it_ad a:hover{text-decoration:none}.one .bsa_it_ad .bsa_it_t{display:block;font-size:12px;font-weight:bold;color:#212121;line-height:125%;padding:0 0 5px 0}.one .bsa_it_ad .bsa_it_d{display:block;font-size:11px;color:#434343;font-size:12px;line-height:135%}.one .bsa_it_ad .bsa_it_i{float:left;margin:0 15px 10px 0}.one .bsa_it_p{display:block;text-align:right;position:absolute;bottom:10px;right:15px}.one .bsa_it_p a{font-size:10px;color:#666;text-decoration:none}.one .bsa_it_ad .bsa_it_p a:hover{font-style:italic}');this.bsaonecss=1;o+='<div class="bsa_it one">';for(i=0,a;i<c.length&&(a=bsa.getads(c[i],1)[0]);i++,(j++,o+='<div class="bsa_it_ad ad'+i+' '+(i%2===0?'even':'odd')+'" id="bsa_'+a.id+'"><a '+bsa.link(a.id,z.id,a.link.replace('[timestamp]',ts))+' target="_blank"><span class="bsa_it_i"><img src="'+a.img.replace('[timestamp]',ts)+'" width="'+z.width+'" height="'+z.height+'" alt="'+a.alt+'" \/><\/span><\/a><a '+bsa.link(a.id,z.id,a.link)+' target="_blank"><span class="bsa_it_t">'+a.alt+'<\/span><span class="bsa_it_d">'+a.text+'<\/span><\/a><div style="clear:both"><\/div><\/div>',t+=a.id+';')){}if(z.model==1&&z.cpmbackfill&&j==0){for(var r=Math.random(),bn=0;bn<z.cpmbackfill.length&&z.cpmbackfill[bn]&&z.cpmbackfill[bn][0]<r;r-=z.cpmbackfill[bn++][0]){}if(z.cpmbackfill[bn]&&z.cpmbackfill[bn][0]&&z.cpmbackfill[bn][1].length>0){o+='<iframe width="'+w+'" height="'+h+'" id="backfill_'+z.id+'_frame" src="'+z.cpmbackfill[bn][1]+'" frameborder="0" class="bsap_backfillframe" scrolling="no"><\/iframe>';backfilled=true}}for(i=j;!backfilled&&(typeof(bsa.callback)=='function')&&i<z.nads;i++,o+=bsa.callback(z.id,i-1,z.nads)||''){}if(c.length>0)o+='<span class="bsa_it_p"><a href="http:\/\/buysellads.com\/buy\/detail\/'+z.siteid+'\/zone\/'+z.id+'?utm_source=site_'+z.siteid+'&utm_medium=website&utm_campaign=imagetext&utm_content=zone_'+z.id+'">ads by BSA<\/a>'+(z.carrousel?'<br/><a href="#" class="prevad" onclick="_bsap.inv['+z.id+']()">&larr;<\/a> <a href="#" class="nextad" onclick="_bsap.inv['+z.id+']()">&rarr;<\/a>':'')+'<\/span><\/div>'}else if(tf==2){c.length==0&&ah&&c.push({id:-i,link:'http:\/\/buysellads.com\/buy\/detail\/'+z.siteid+'\/zone\/'+z.id,title:'Advertise Here',text:'Advertise in this spot with Online Advertising Marketplace'});this.textlinkscss==1||z.nostyle==1||css('.bsa_padint{font-family:helvetica,arial,verdana,sans-serif;font-size:12px;position:relative}.bsa_padint ul.bsa_ads{list-style-type:none;margin:0;padding:0}.bsa_padint ul.bsa_ads li{margin:0;padding:0;position:relative}.bsa_padint ul.bsa_ads em.bt{color:#06c;font-size:14px;font-weight:700;text-decoration:underline}div.bsa_idb{border-top:1px solid #f1f1f1;bottom:0;color:#999;font-size:10px;height:5px;left:0;margin:0;padding:0;position:absolute;width:100%}div.bsa_idb .bsa_idl{background:#fff;bottom:2px;line-height:7px;padding:0 3px;position:absolute;right:5px}div.bsa_idb a{color:#999;height:3px;margin:0;padding:0;text-decoration:none}div.bsa_idb a em{font-style:normal}div.bsa_idb a:hover{background:none;color:#666}div.bsa_idb a:hover em{font-style:italic}ul.bsa_ads li *{cursor:pointer}.bsapvariable{overflow:hidden;visibility:visible;width:auto}.bsapvariable ul.bsa_ads li{float:left;padding:5px;text-align:left;width:250px}div.bsapvariable ul.bsa_ads li a,div.bsapvariable div.bsa_idb span.bsa_idl,div.bsapvariable div.bsa_idb{clear:both;height:auto;margin:0;position:relative;text-decoration:none;width:250px}.bsa_padint ul.bsa_ads em{display:block;font-style:normal}div.bsapvariable .bsa_padint ul.bsa_ads em.bd{color:black;text-decoration:none}div.bsapvariable div.bsa_idb a{display:block;height:13px;text-align:right;width:250px}.bsa_padint ul.bsa_ads a:hover,.bsa_padint ul.bsa_ads a:hover div.bwr{background-color:#f7f7f7}');this.textlinkscss=1;o+='<div class="bsap_unit bsapvariable"><div class="bsa_padint"><ul class="bsa_ads">';for(i=0,a;i<c.length&&(a=bsa.getads(c[i],1)[0]);i++,o+='<li class="bsapt_'+a.id+' ad'+i+' '+(i%2===0?'even':'odd')+'"><a '+bsa.link(a.id,z.id,a.link)+' target="_blank"><div class="bwr"><em class="bt">'+a.title+'<\/em><em class="bd">'+a.text+'<\/em><\/div><\/a><\/li>',t+=a.id+';'){}for(i=j;(typeof(bsa.callback)=='function')&&i<z.nads;i++,o+=bsa.callback(z.id,i-1,z.nads)||''){}o+='<\/ul>';if(c.length>0)o+='<div class="bsa_idb"><span class="bsa_idl"><a href="http:\/\/buysellads.com\/buy\/detail\/'+z.siteid+'?utm_source=site_'+z.siteid+'&utm_medium=website&utm_campaign=textdesc&utm_content=zone_'+z.id+'" target="_blank">ads by <em>BSA<\/em><\/a><\/span><\/div><\/div><\/div>'}else if(tf==4){css('div.bsap_'+z.id+'{'+z.bannerstyles.join("\n")+'}');var a=c.length>0?bsa.getads(c[0],1)[0]:null;if(a&&(Math.random()*100>(z.model==1&&z.nads>c.length?(100-c[0].per):empty))){b.style.backgroundImage='url('+a.img.replace('[timestamp]',ts)+')';b.className=b.className+' bsa_hasads';b.onclick=function(e){var e=e||window.event,target=e.target||e.srcElement;if(target.getAttribute('id')==('bsap_'+z.id))window.location=bsa.tracker('click.go',a.id,z.id,'','','&link='+a.link.replace('[timestamp]',ts))};t+=a.id}}if(o&&!b.innerHTML.length)b.innerHTML=o;_bsap.rocks('imp',t,z.id)})},getads:function(d,n){var b='',c,a=d.ads,tdiff=0,ret=[],got=[],i;if(!a)return[d];if(a.length<=n||a.length===1)return this.shuffle(a);for(i=0;i<a.length;i++)b+=new Array(a[i].per+1).join(i+',');b=b.substr(0,b.length-1).split(',');while(ret.length<n&&i++<n*100&&(c=a[b[Math.floor(Math.random()*b.length)]]))if(n===1)return[c];else if(!got[c.id]){got[c.id]=1;ret.push(c)}return ret},shuffle:function(o){for(var j,x,i=o.length;i;j=parseInt(Math.random()*i),x=o[--i],o[i]=o[j],o[j]=x);return o},filter:function(fs,fn){var s=['all'];if(!fs)fn(s);if(fs.os&&fs.os[(os=(/(win|mac|linux|iphone|blackberry|pike)/.exec(navigator.platform.toLowerCase())||['?'])[0])])s.push(os);if(fs.geo){IAmGot.push(fn);var got=0,c=document.cookie,i=c.indexOf('country=');IAm=function(y){if(y!=='?'){var d=new Date(),nd=+d;d.setTime(30*3600000+nd);document.cookie='country='+y+'; expires='+d.toGMTString()+'; path=\/'}if(IAmGot.length>0){s.push(y);for(var li=0;li<IAmGot.length;li++)IAmGot[li](s);IAmGot=[]}};if(i>=0)IAm(c.substring(i+7+1).split(';')[0]);else{var e=document.createElement('script');e.type='text\/javascript';e.src=document.location.protocol+'\/\/stats.buysellads.com\/country.php';document.getElementsByTagName('head').item(0).appendChild(e);setTimeout(function(){IAm('?')},100)}}else fn(s)},interpret_json:function(a){this.jz=typeof this.jz=='object'?this.jz.concat(a.zones):a.zones;this.deploy()},rocks:function(t,b,z){var u=this.gen('bsau',30),s=this.gen('bsas',1/48),img=new Image();img.src=this.tracker(t+'.gif',b,z,u,s,'')},link:function(b,z,l){return'href="'+this.tracker('click.go',b,z,'','','&link='+l)+'" onmouseover="window.status = \''+l+'\'; return true;" onmouseout="window.status=\'\'; return true;"'},tracker:function(t,b,z,u,s,additional){return'http:\/\/stats.buysellads.com\/'+t+'?z='+z+'&b='+b+'&g='+u+'&s='+s+'&sw='+screen.width+'&sh='+screen.height+'&br='+this.br()+'&r='+Math.random()+additional},br:function(){var a=navigator.userAgent,p=navigator.platform,m=function(r,h){for(var i=0;i<h.length;i++)r=r.replace(h[i][0],h[i][1]);return r},i=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['Minefield','Firefox']]):a).toLowerCase();return[(/(camino|chrome|firefox|opera|msie|safari)/.exec(i)||['','?'])[1],parseFloat((/(camino|chrome|firefox|opera|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/.exec(i)||[0,0,0,0])[3],10)||0,(/(win|mac|linux|iphone|blackberry|pike)/.exec(p.toLowerCase())||['?'])[0]]},gen:function(w,e){var c=document.cookie,i=c.indexOf(w+'=');if(i>=0)return c.substring(i+w.length+1).split(';')[0];else{var d=new Date(),nd=+d;d.setTime(e*3600000+nd);document.cookie=w+'='+(nd+Math.random().toString().substr(2,7))+'; expires='+d.toGMTString()+'; path=\/';return-1}},hasFlash:function(){var gotit=false;try{var fo=new ActiveXObject('ShockwaveFlash.ShockwaveFlash');if(fo)gotit=true}catch(e){if(navigator.mimeTypes["application/x-shockwave-flash"]!=undefined)gotit=true}return gotit}};_bsap_loadedme=1;if(typeof(_bsap_loadme)==='object'){for(var _bi=0;_bi<_bsap_loadme.length;_bi++){_bsap_loadme[_bi]();_bsap_loadme[_bi]=function(){}}}if(document.addEventListener)document.addEventListener('DOMContentLoaded',function(){_bsap.exec()},false);else if((/msie/.test(navigator.userAgent.toLowerCase()))&&window==top){(function(){try{document.documentElement.doScroll('left')}catch(error){setTimeout(arguments.callee,0);return}_bsap.exec()})();window.document.onreadystatechange=function(){if(window.document.readyState=='complete'){window.document.onreadystatechange=null;_bsap.exec()}}}IAmGot=[];oldonload=window.onload;window.onload=function(){_bsap.exec();if(oldonload)oldonload()};_bsap.exec();
    Its pretty long. Honestly I have no idea how to read it. Does it look like anything bad could come from running the script twice?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Why do you want to include the code twice?

    If the second script is the same as the first, it will overwrite the first one.

    If all else fails, read the instructions. "Help files on the BuySellAds website says it should only appear once on a page." OK?


    It is your responsibility to die() if necessary….. - PHP Manual

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    133
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Why do you want to include the code twice?

    If the second script is the same as the first, it will overwrite the first one.

    If all else fails, read the instructions. "Help files on the BuySellAds website says it should only appear once on a page." OK?


    It is your responsibility to die() if necessary….. - PHP Manual
    The reason is, I'd like to place the code all together in 1 code on an ad server.
    Sometimes there will be 1 ad from BSA, sometimes there will be 2, sometimes there will b 0. What I'd like to know, is if the ad code shows up twice, if it will cause problems.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    One piece of JavaScript only needs to appear in the page once.

    All JavaScript with very few exceptions should be placed immediately before the </body> tag.

    The only exceptions are:

    1. Scripts that can transfer to a different page before the current page finishes loading - which need to go in the head.
    2. Antiquated ad scripts that use document.write where you have not implemented postscribe.js or an equivalent script that captures the content of document.write statements and outputs them into a specified id higher up in the page - such antiquated ad scripts need to go at the spot where the ad appears.

    Neither of those applies with the code posted in this thread (so the script can and should be attached at the bottom of the body). The image the script generates is always added to the end of the body so the only effect of placing the code higher in the page will be to slow the loading of the rest of the page. You can call the script as many times as you like at the end of the body and for each time you call it an additional copy of the ad will appear at the bottom of the page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •