Announcement

Collapse
No announcement yet.

Random Image when new page opens .. that old chest nut

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Random Image when new page opens .. that old chest nut

    Hi Guys,

    I wanted to try the random images suched by Norman in the following thread http://community.actinic.com/showpos...3&postcount=17

    I like the idea, keeps it with Actinic however it does not work for me, I did reduce it down to 2 images, I wondered if I got something wrong so copied and pasted the original code still no joy.

    I have had little success and was after suggestions.


    The test site is found at
    http://www.organicplants.co.uk/acata...Nurseries.html

    All very rough as I started back with clean templates, the errors are:

    missing ) after argument list
    P_index.html (line 287)
    if (showlink) document.write('<a href="' + links<Actinic:Variable Name = 'idx'/> + '">');
    missing ) after argument list
    P_index.html (line 305)
    if (showlink) document.write('<a href="' + links<Actinic:Variable Name = 'idx'/> + '">');
    missing ) after argument list
    Organic_plants_fo... (line 55)
    if (showlink) document.write('<a href="' + links<Actinic:Variable Name = 'idx'/> + '">');
    missing ) after argument list
    Organic_plants_fo... (line 61)
    if (showlink) document.write('<a href="' + links<Actinic:Variable Name = 'idx'/> + '">');
    Any help would be appreciated kind regards Mash
    Mash

    #2
    Neither link you've given us works.

    Try changing.

    <Actinic:Variable Name = 'idx'/>

    to

    <actinic:variable name="idx" encoding="perl" selectable="false" />
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Ok the test page link is this

      Test Site

      And the thread link is

      Norman's Random images

      Whole thread Random images

      I will do those changes thanks Mash
      Mash

      Comment


        #4
        You're the victim of an Actinic Bug. Anything between square brackets is being accidentally converted into a variable reference. E.g.

        links[idx]

        becomes

        links[<actinic:variable name="idx" />]

        which aint JavaScript.

        The fix is to use

        links[ idx ]

        as those spaces seem to keep Actinic from interfereing.


        The V8 JavaScript should be as per below

        Code:
        <script language=JavaScript>
        <!--
        if (showlink) document.write('<a href="' + links[ idx ] + '">');
        document.write('<img border=0 src="' + images[ idx ] + '">');
        if (showlink) document.write('<\a>');
        //-->
        </script>
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Norman you are too quick for me just typing a reply with a few questions and bame a solution which is superb, currently does make the image appear twice! Just uploading to see if there is any difference.

          I do have another question regarding placing the images, I currently place all my images in Actinic/Images/etc., that is fine for all the products etc. however, for this case it cause the following issue comment:

          Some filenames conflict. All files being sent to the web site must have unique names. Please check the list of files in Design | Additional Files.

          Some of the following files must be renamed before an upload can occur. Once the files are renamed, reselect them in the Actinic.

          C:\Program Files\Actinic v8\Sites\Site1\Images\\Homepage\\RunnerBeans-400.jpg
          C:\Program Files\Actinic v8\Sites\Site1\Images\Homepage\RunnerBeans-400.jpg
          When they are placed in the root of Actinic it is fine. Ideally I would like to tidy them away in Images folder. Is that possible?

          Have upload, now down to one error and two images.

          missing ) after argument list
          Organic_plants_fo... (line 54)
          if (showlink) document.write('<a href="' + links<Actinic:Variable Name = 'idx'/> + '">');
          Your help is so appreciated, thank you. Good to have a break I guess there is some festive stuff I should be doing.

          Back later thanks M
          Mash

          Comment


            #6
            You appear to have the second lump of JavaScript repeated 3 times. The first with the original problem and the second two fixed and working. Get rid of the 1st 2 ocurrences and all will be well.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Posting the code from the V7 Support which has een converted to V8, original thread

              Code:
              </script> 
              
              var cvimages=new Array('<actinic:variable name="IMAGE1" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE2" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE3" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE4" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE5" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE6" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE7" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE8" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE9" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE10" encoding="perl" selectable="false" />');
              
              var cvlinks=new Array('<actinic:variable name="LINK1" encoding="perl" selectable="false" />','<actinic:variable name="LINK2" encoding="perl" selectable="false" />','<actinic:variable name="LINK3" encoding="perl" selectable="false" />','<actinic:variable name="LINK4" encoding="perl" selectable="false" />','<actinic:variable name="LINK5" encoding="perl" selectable="false" />','<actinic:variable name="LINK6" encoding="perl" selectable="false" />','<actinic:variable name="LINK7" encoding="perl" selectable="false" />','<actinic:variable name="LINK8" encoding="perl" selectable="false" />','<actinic:variable name="LINK9" encoding="perl" selectable="false" />','<actinic:variable name="LINK10" encoding="perl" selectable="false" />');
              
              <script language=JavaScript>
              var cvimages=new Array('<actinic:variable name="IMAGE1" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE2" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE3" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE4" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE5" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE6" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE7" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE8" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE9" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE10" encoding="perl" selectable="false" />');
              
              var cvlinks=new Array('<actinic:variable name="LINK1" encoding="perl" selectable="false" />','<actinic:variable name="LINK2" encoding="perl" selectable="false" />','<actinic:variable name="LINK3" encoding="perl" selectable="false" />','<actinic:variable name="LINK4" encoding="perl" selectable="false" />','<actinic:variable name="LINK5" encoding="perl" selectable="false" />','<actinic:variable name="LINK6" encoding="perl" selectable="false" />','<actinic:variable name="LINK7" encoding="perl" selectable="false" />','<actinic:variable name="LINK8" encoding="perl" selectable="false" />','<actinic:variable name="LINK9" encoding="perl" selectable="false" />','<actinic:variable name="LINK10" encoding="perl" selectable="false" />');
              
              var images=new Array();
              var links=new Array();
              for (var i=0; i < cvimages.length; i++) { if (cvimages[i] != '') { images.push(cvimages[i]); links.push(cvlinks[i]); } }
              idx = Math.floor(Math.random()*images.length - 0.01);
              showlink = (links[idx] != '');
              </script>
              Norman's fix
              Code:
              <script language=JavaScript>
              <!--
              if (showlink) document.write('<a href="' + links[ idx ] + '">');
              document.write('<img border=0 src="' + images[ idx ] + '">');
              if (showlink) document.write('<\a>');
              //-->
              </script>
              Just wanted to pull it all togther remove the V8 stuff relating to the V7 thread.
              Mash

              Comment


                #8
                Wanted to add Alt text by setting up a new array
                var cvtexts=new Array('<actinic:variable name="TEXT1" encoding="perl" selectable="false" />', etc.
                I could not get that to work.

                Get the images from another directory would be useful to sort out but it is working well.

                Thanks for all your help.
                Last edited by mash; 12-Jan-2009, 07:40 PM. Reason: Spelling mistake
                Mash

                Comment


                  #9
                  For testing simply preview your page, then copy / paste the URL into Firefox. Use its Tools / JavaScript or Error Console to see what's wrong.

                  Post #7 has a bug or 2.

                  Replace

                  Code:
                  </script> 
                  
                  var cvimages=new Array('<actinic:variable name="IMAGE1" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE2" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE3" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE4" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE5" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE6" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE7" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE8" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE9" encoding="perl" selectable="false" />','<actinic:variable name="IMAGE10" encoding="perl" selectable="false" />');
                  
                  var cvlinks=new Array('<actinic:variable name="LINK1" encoding="perl" selectable="false" />','<actinic:variable name="LINK2" encoding="perl" selectable="false" />','<actinic:variable name="LINK3" encoding="perl" selectable="false" />','<actinic:variable name="LINK4" encoding="perl" selectable="false" />','<actinic:variable name="LINK5" encoding="perl" selectable="false" />','<actinic:variable name="LINK6" encoding="perl" selectable="false" />','<actinic:variable name="LINK7" encoding="perl" selectable="false" />','<actinic:variable name="LINK8" encoding="perl" selectable="false" />','<actinic:variable name="LINK9" encoding="perl" selectable="false" />','<actinic:variable name="LINK10" encoding="perl" selectable="false" />');
                  
                  <script language=JavaScript>
                  with just

                  <script type="text/javascript">


                  and change

                  showlink = (links[idx] != '');

                  to be

                  showlink = (links[ idx ] != '');

                  just in case Actinic decides to mess with that bracketed text.
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #10
                    Hi have been testing it in Firefox, the script in #7 works fine with no errors, however will change it. Thanks M
                    Mash

                    Comment


                      #11
                      Hi and good morning,

                      I am trying out banner ideas and getting stuck, thought I would try the Script posted by Kermy either side to the logo.

                      In the past I use this space for fixed banner images, if you wanted to update you just over wrote the file with a new image, both having image maps to a suitable link.

                      To make the site more dynamic or fresher, I thought I would try the script above, however, it loads 1 image but not others? Changed the original script so I could have a left and right banner, may have missed some thing but is not producing errors!

                      Code:
                      <script type="text/javascript">
                      <!--
                      function bannerleft(){
                      var banner=new Array();
                      var link=new Array();
                      var alt=new Array();
                      var win=new Array();
                      
                      bannerleft[bannerleft.length]="Banner-L-Cabbage.jpg";
                      link[link.length]="";
                      alt[alt.length]="Organic Plants online website www.organicplants.co.uk";
                      win[win.length]=false;
                      
                      bannerleft[bannerleft.length]="Banner-L-Onions.jpg";
                      link[link.length]="";
                      alt[alt.length]="Organic Plants online website www.organicplants.co.uk";
                      win[win.length]=false;
                      
                      bannerleft[bannerleft.length]="Banner-L-Organic-Lettuce.jpg";
                      link[link.length]="http://www.organicplants.co.uk";
                      alt[alt.length]="Organic Plants online website www.organicplants.co.uk";
                      win[win.length]=true;
                      
                      bannerleft[bannerleft.length]="Banner-L-Organic-plants.gif";
                      link[link.length]="";
                      alt[alt.length]="Organic Plants online website www.organicplants.co.uk";
                      win[win.length]=true;
                      
                      var num=Math.floor(Math.random()*(bannerleft.length))
                      if (link[num]){
                      	str="<a href=\""+link[num]+"\"";
                      	if (win[num]){
                      		str+=" target=\"blank\"";
                      		}
                      	str+="><img src=\"http://www.organicplants.co.uk/images/banners/"+bannerleft[num]+"\" border=\"0\" alt=\""+alt[num]+"\" />";
                      	}
                      else{
                      	str="<img src=\"http://www.organicplants.co.uk/images/banners/"+bannerleft[num]+"\" border=\"0\" alt=\""+alt[num]+"\" />";
                      	}
                      return(str);
                      }
                      // -->
                      </script>
                      I split the original table in to three and place the follow script for the left banner in the first cell.
                      Code:
                      <script type="text/javascript">
                      document.write(bannerleft());
                      </script>
                      Any ideas?
                      Mash

                      Comment


                        #12
                        Mash,

                        I see some missing code. There's no </a> if you use a link. Try changing
                        Code:
                        	str+="><img src=\"http://www.organicplants.co.uk/images/banners/"+bannerleft[num]+"\" border=\"0\" alt=\""+alt[num]+"\" />";
                        to be
                        Code:
                        	str+="><img src=\"http://www.organicplants.co.uk/images/banners/"+bannerleft[num]+"\" border=\"0\" alt=\""+alt[num]+"\" /></a>";
                        As to why it isn't working. When you renamed the function name to bannerleft you also changed the banner array name in a zillion places. Change ALL bannerleft back to banner above except the function name.
                        Norman - www.drillpine.biz
                        Edinburgh, U K / Bitez, Turkey

                        Comment


                          #13
                          Also if you are using this in V8, you have to put a space after every [ and before every ]. E.g.

                          link[link.length]="";

                          becomes

                          link[ link.length ]="";

                          And for testing look at your pages in Firefox and use its Tools / (Javascript/Error) Console to get decent diagnostics.
                          Norman - www.drillpine.biz
                          Edinburgh, U K / Bitez, Turkey

                          Comment


                            #14
                            I have also posted a V8 version of my similar patch. If you use mine, you won't have to upload these images as Actinic will do it for you.

                            It's also easier to maintain as all the data is held in Variables and you won't have to edit source code when you change something.

                            You could also do this to the patch above by replacing those hard-coded filenames, links, alts, etc, by Actinic Variables.
                            Norman - www.drillpine.biz
                            Edinburgh, U K / Bitez, Turkey

                            Comment


                              #15
                              Have tried out your solution and placed it in a fragment works very well. Have not added any more images variables at the moment.

                              Just trying to use the banner spaces either side of the main logo. In the idea world I would have single image which could see as 1 or two smaller images and image map to link agin either as a whole or when small to either image.

                              This can be seen on Current live site but this is hard coded, again I could change this to variables.

                              Nice to have changing banners to make it more interesting.

                              Down to two errors.

                              unterminated string literal
                              Organic_plants_fo... (line 70)
                              str+="><img src=\"http://www.organicplants.co.uk/images/banners/"+banner[ num ]+"\" border=\"0\" alt=\""+alt[ num ]+"\" /></a>;
                              nullOrganic_plants_fo... (line 118)
                              bannerright is not defined
                              Organic_plants_fo... (line 118)
                              I do have banner right and that was why I had the bannerleft, when it is trail and error / closer to error and error I thought it was logical.
                              Mash

                              Comment

                              Working...
                              X