rotation - Javascript; Calling src within the script? - Stack Overflow

I'm making a simple affiliate ad rotation JavaScript. I'm still new to JavaScript and don

I'm making a simple affiliate ad rotation JavaScript. I'm still new to JavaScript and don't fully understand it so bear with me.

Google's adsense is split into 2 parts, one to set the variables, and the next to get the script. Then Amazon has an iframe to get it's ad's. All I want to do is use a random number from 1 to 2 (will be larger later) that will randomly select one of them to display on my localhost.

<script type="text/javascript"><!--
/* Custom footer */

select = rand(2);

if(select == 1){
     google_ad_client = "-----------";
     google_ad_slot = "---------";
     google_ad_width = ---;
     google_ad_height = --;

     //get this google 
     <script ...src=".js

} else {
         <iframe src=";o=1&p=48&l=ur1&category=amazonhomepage&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
}
</script>

I'm making a simple affiliate ad rotation JavaScript. I'm still new to JavaScript and don't fully understand it so bear with me.

Google's adsense is split into 2 parts, one to set the variables, and the next to get the script. Then Amazon has an iframe to get it's ad's. All I want to do is use a random number from 1 to 2 (will be larger later) that will randomly select one of them to display on my localhost.

<script type="text/javascript"><!--
/* Custom footer */

select = rand(2);

if(select == 1){
     google_ad_client = "-----------";
     google_ad_slot = "---------";
     google_ad_width = ---;
     google_ad_height = --;

     //get this google 
     <script ...src="http://pagead2.googlesyndication./pagead/show_ads.js

} else {
         <iframe src="http://rcm.amazon./e/cm?t=------&o=1&p=48&l=ur1&category=amazonhomepage&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
}
</script>
Share Improve this question edited Aug 31, 2015 at 15:07 Mogsdad 45.8k21 gold badges163 silver badges286 bronze badges asked Jan 6, 2011 at 17:39 ChenelleChenelle 1871 gold badge6 silver badges16 bronze badges 3
  • I'm not quite sure what you're asking... – NickAldwin Commented Jan 6, 2011 at 17:47
  • First make sure what you are trying to do doesn't break any adsense policies. Any modification to their generated script code is in violation with their policy. – O.O Commented Jan 6, 2011 at 17:49
  • Breaking their policy? I thought that meant modifying the data from their show_ads.js – Chenelle Commented Jan 6, 2011 at 20:16
Add a ment  | 

3 Answers 3

Reset to default 2

You need to use document.write("<html>or text</html") to write html out to the page, though for the iframe i would suggest putting it inside another div

<script type="text/javascript"><!--
/* Custom footer */

var select = Math.floor(Math.random()*2);

if(select == 1){
     google_ad_client = "-----------";
     google_ad_slot = "---------";
     google_ad_width = ---;
     google_ad_height = --;

     //get this google 
     document.write("<script ...src='http://pagead2.googlesyndication./pagead/show_ads.js' />");

} else {
     document.getElementById('adContainer').innerHTML('<iframe src="http://rcm.amazon./e/cm?t=------&o=1&p=48&l=ur1&category=amazonhomepage&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>');
}
</script>

You need to use document.write("stringtowritetodocument"); in order to get JavaScript to write anything to the document.

So, inside your if:

document.write('<script type="text/javascript" src="http://pagead2.googlesyndication./pagead/show_ads.js"></script>');

Also, once this grows in plexity, you may need to look out for this: JavaScript's document.write Inline Script Execution Order

What you want may also be acplished better with some server-side code, if that is available to you.

Have you tried Document.Write()?

e.g. Document.Write("<p>Your HTML Here</p");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745435071a4627570.html

相关推荐

  • rotation - Javascript; Calling src within the script? - Stack Overflow

    I'm making a simple affiliate ad rotation JavaScript. I'm still new to JavaScript and don

    10小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信