Announcement

Collapse
No announcement yet.

Random Image when new page opens ...

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

    #31
    Part of the core design of JavaScript is that it has no access to the filesystem. This means that it is unable to load any information from external files. You could possibly do some trickery with an IFRAME and set it's source (a small HTML page for each product) dynamically using JavaScript.

    What I'd recommend doing is to extend the existing JavaScript to load another array containing a list of CUSTOMVAR:TEXT1 ... TEXT6 and document.write that out. It might be best to use double quoted names, so that single quotes in the text don't cause JavaScript errrors.

    E.g.
    Code:
    var cvtext=new Array("CUSTOMVAR:TEXT1","CUSTOMVAR:TEXT2","CUSTOMVAR:TEXT3","CUSTOMVAR:TEXT4","CUSTOMVAR:TEXT5",
                         "CUSTOMVAR:TEXT6","CUSTOMVAR:TEXT7","CUSTOMVAR:TEXT8","CUSTOMVAR:TEXT9","CUSTOMVAR:TEXT10");
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #32
      Hi Norman, thanks for the quick reply.
      I realised that your code was flexible with regards to displaying as much information as i wanted, but the honest answer is my javascript is not up to scratch (my only formal training is VB), and wasnt to keen on the idea of playing around with it. I'll have a go at modifiying your script to display all the information im after and let you know who it goes.

      Many thanks

      Pete
      www.discoSuperstore.co.uk
      Portsmouth Sound & Light. The South's No.1 DJ Store

      Comment


        #33
        When testing JavaScript, use Firefox ( www.mozilla.com) and it's Tools / JavaScript console to get meaningful diagnostics. Just do an Actinic Preview and paste the URL from IE into Firefox.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #34
          Hello again all, i now have a working script so would like to thank you all for your help.
          However i do have one new question with regards to Search Engines, am i right in believing that because these images are displayed using javascript code, a SE will not recognise the links/text and images as being there?

          Pete @ PSL
          www.discoSuperstore.co.uk
          Portsmouth Sound & Light. The South's No.1 DJ Store

          Comment


            #35
            That's correct. JavaScript generated links won't be spiderable.

            In these cases it's always a good idea to generate a Site Map (via Design / Options / Sections). And make sure you have a direct link to the Site Map for search engines to follow. This way all your pages will be indexable.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #36
              any ideas why adding a random function to the page would stop a DHTML menu from loading?
              I've tried using the firefox Javascript Console but dont really understand its results.

              The test page i have set up the moment is

              http://www.discosuperstore.co.uk/Pete.html

              Many thanks

              Pete@PSL
              www.discoSuperstore.co.uk
              Portsmouth Sound & Light. The South's No.1 DJ Store

              Comment


                #37
                Looks like you might have this licked already, but I've successfully used this on a client’s site in one of the Actinic Templates (I created a separate template for a particular product with this included as part of the template):

                http://kaosweaver.com/extensions/det...hp?id=5&cid=13

                It’s really easy to use, you can add custom links to the images and ALT text too. Nice! Its actually a DW plugin so works really easily. You might need to manually change the image link in the source code though as I have had a couple of problems in the past with it trying to link to a local file path.

                Hope this helps?

                Cheers
                Charlie

                _________________________
                B&M Design & Advertising Ltd
                www.bm-group.co.uk

                Comment


                  #38
                  Pete, the page http://www.discosuperstore.co.uk/Pete.html contains numerous NETQUOTEVAR: type tags.

                  This implies that this isn't an Actinic generated page but one you've made yourself probably based on an Actinic primary template.

                  This will undoubtedly be causing errors, especially JavaScript ones. For example your <body...> tag has
                  Code:
                  <BODY OnLoad="NETQUOTEVAR:ONLOAD;MM_preloadImages('http://www.discosuperstore.co.uk/graphics/mainmenu/b_faqs_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_home_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_about_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_ordering_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_basket_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_links_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_contact_over.gif','http://www.discosuperstore.co.uk/graphics/mainmenu/b_search_over.gif')">
                  and that inital NETQUOTEVAR:ONLOAD; will cause a JavaScript error and kill of the rest of that line.
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #39
                    Hi Norman, the page Pete.html is an exact copy of the homepage (Copied the file from my site1 directory) that is currently running on line, the only difference between the two pages (that i am aware of), is the additional javascript i added to make the random images display.

                    Could it be that i have manually uploaded this file to the server as opposed to putting it there via actinic?

                    I didnt think this would have mattered as the dhtml menu is not a feature/associated with actinic in anyway.

                    Thanks for all your help so far.
                    www.discoSuperstore.co.uk
                    Portsmouth Sound & Light. The South's No.1 DJ Store

                    Comment


                      #40
                      Hi seem to have fixed it.

                      I have to create a new page in actinic, and tell it to use my page as a template. Once uploaded it clears the fault.

                      Thanks All

                      Pete @ PSL
                      www.discoSuperstore.co.uk
                      Portsmouth Sound & Light. The South's No.1 DJ Store

                      Comment


                        #41
                        Hi all, i know this is more a javascript question but as its related to what we achieved here, i will post it in this thread.

                        Have successfully created the script to display random images, however because i am displaying 6 images from the same array on the homepage there is a high chance of product duplication.

                        How would i write a javascript loop to ensure that all 6 random numbers are different.

                        In VB i would usually use a DO LOOP, and repeat it until all 6 variables are different. Not sure how to do this in javascript.

                        Many thanks

                        Pete
                        www.discoSuperstore.co.uk
                        Portsmouth Sound & Light. The South's No.1 DJ Store

                        Comment


                          #42
                          Code:
                          var arr=new Array();
                          for (i=0;i<6;i++){
                          	num=randomNumber();
                          	while (isIn(arr,num)){
                          		num=randomNumber();
                          		}
                          	arr[i]=num;
                          	}
                          	
                          function isIn(arr,v){
                          for (j=0;j<arr.length;j++){
                          	if (arr[j]==v) return true;
                          	}
                          return false;
                          }
                          
                          function randomNumber(){
                          var X=10;
                          return Math.floor(Math.random()*(X-1))
                          }
                          This will create an array arr of 6 distinct, random values between 0-10.
                          www.gbradley.co.uk
                          Web Development, Actinic Patches, Scripts & more

                          Comment


                            #43
                            Kermy Thank You, just a couple of questions.

                            function randomNumber(){
                            var X=10;
                            return Math.floor(Math.random()*(X-1))

                            Im assuming the Line var X=10 is were i would enter the maximum value , can i input a line

                            return Math.floor(Math.random()*myimages.length)

                            and ignore the X variable completely?

                            And how do i reference the 6 individual numbers?

                            At the moment i create 6 invidual random numbers
                            Product1 = (1st Random Number)
                            Product2 = (2nd Random Number)

                            What would i replace the Product1 (1-6) variable reference with?
                            www.discoSuperstore.co.uk
                            Portsmouth Sound & Light. The South's No.1 DJ Store

                            Comment


                              #44
                              Yup, assuming your image names are held in an array called myimages, you could use
                              Code:
                              var arr=new Array();
                              for (i=0;i<6;i++){
                              	num=Math.floor(Math.random()*myimages.length);
                              	while (isIn(arr,num)){
                              		num=Math.floor(Math.random()*myimages.length);
                              		}
                              	arr[i]=num;
                              	}
                              	
                              function isIn(arr,v){
                              for (j=0;j<arr.length;j++){
                              	if (arr[j]==v) return true;
                              	}
                              return false;
                              }
                              Each random number is held in the array called arr. So arr[0] would give the first number, arr[1] the second number and so on. To get to your filenames, you would use myimages[arr[0]], myimages[arr[1]] etc.
                              www.gbradley.co.uk
                              Web Development, Actinic Patches, Scripts & more

                              Comment


                                #45
                                Hi Mash,

                                Since you are adapting the code for v8, v8 does not use "CUSTOMVAR", instread it using "<actinic:variable name="variable name" />"
                                So looking at your code, you would need to change the:

                                Code:
                                var cvimages=new Array('CUSTOMVAR:IMAGE1','CUSTOMVAR:IMAGE2','CUSTOMVAR:IMAGE3','CUSTOMVAR:IMAGE4','CUSTOMVAR:IMAGE5',
                                'CUSTOMVAR:IMAGE6','CUSTOMVAR:IMAGE7','CUSTOMVAR:IMAGE8','CUSTOMVAR:IMAGE9','CUSTOMVAR:IMAGE10');
                                var cvlinks=new Array('CUSTOMVAR:LINK1','CUSTOMVAR:LINK2','CUSTOMVAR:LINK3','CUSTOMVAR:LINK4','CUSTOMVAR:LINK5',
                                'CUSTOMVAR:LINK6','CUSTOMVAR:LINK7','CUSTOMVAR:LINK8','CUSTOMVAR:LINK9','CUSTOMVAR:LINK10');
                                Part to reflect this.

                                Kind Regards
                                Nadeem Rasool
                                SellerDeck Development

                                Comment

                                Working...
                                X