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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rotating code breaks with desired input, stumped

    Thanks for looking!
    I have a widget that lives on a blank/fresh Blogger.com account, and with test pictures, it seems to work fine. However, when I throw in Amazon ads it breaks. Images with links as sample data, rotate and display fine. Changing them to amazon code, they break. What's going on? Am I missing an escape character?

    Code:
    <script language="Javascript" type="text/JavaScript">
    var ad = new Array()
    
    ad[0]='
    <iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
    '
    
    ad[1]='<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
    '
    
    
    function randomorder(targetarray, spacing){
    
    var randomorder=new Array()
    var the_one
    var z=0
    for (i=0;i<targetarray.length;i++)
    randomorder[i]=i
    
    while (z<targetarray.length){
    the_one=Math.floor(Math.random()*targetarray.length)
    if (targetarray[the_one]!="_selected!"){
    document.write(targetarray[the_one]+spacing)
    targetarray[the_one]="_selected!"
    z++
    }
    }
    }
    
    </script>
    
    <script language="Javascript" type="text/javascript" ></script>
    <script>
    randomorder(ad, ' ')
    </script>

  • #2
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know the problem is likely with the ad[] string I am using.
    What am I doing wrong?
    I'm guessing I need to escape a character in the string, but which?

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <script type="text/JavaScript">
    var ad = new Array()
    
    ad[0]='<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'
    
    ad[1]='<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'
    
    
    function randomorder(targetarray, spacing){
    
    var randomorder=new Array()
    var the_one
    var z=0
    for (i=0;i<targetarray.length;i++)
    randomorder[i]=i
    
    while (z<targetarray.length){
    the_one=Math.floor(Math.random()*targetarray.length)
    if (targetarray[the_one]!="_selected!"){
    document.write(targetarray[the_one]+spacing)
    targetarray[the_one]="_selected!"
    z++
    }
    }
    }
    randomorder(ad, '<br>')
    </script>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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