Announcement

Collapse
No announcement yet.

Random Image when new page opens ...

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

    #61
    Originally posted by mash View Post
    Hi,

    I was wondering if it was possible to place this script from Post #15 in to an external file instead of placing it in the <head> section of the page.

    Any thoughts would be appreciated, thanks Mash
    You can place any javascript into an external .js file. Just remember to remove the <script type="text/javascript"> and </script> tags. You will have to call up the script file in your templates or html using the following inside the <head> section:
    <SCRIPT type="text/javascript" src="acatalog/myscript.js"></script>

    To speed up page load times, you should merge any seperate .js files into one or two files. You could just add the script code from post 15 to the actinic .js files (actiniccore.js and actinicextras.js in V7)

    Comment


      #62
      I thought you could but was unsure how to link the two aspects together, so to be doubly sure:-

      Code in a file called "script.js"
      function banner(){
      var banner=new Array();
      var link=new Array();
      var alt=new Array();
      var win=new Array();

      banner[banner.length]="freeshipping.jpg";
      link[link.length]="";
      alt[alt.length]="ALT text for shipping image";
      win[win.length]=false;

      banner[banner.length]="offer.jpg";
      link[link.length]="http://www.mysite.com/offer.htm";
      alt[alt.length]="ALT text for offer image";
      win[win.length]=true;

      var num=Math.floor(Math.random()*(banner.length))
      if (link[num]){
      str="<a href=\""+link[num]+"\"";
      if (win[num]){
      str+=" target=\"blank\"";
      }
      str+="><img src=\"http://www.diskdepot.co.uk/acatalog/banners/"+banner[num]+"\" border=\"0\" alt=\""+alt[num]+"\" />";
      }
      else{
      str="<img src=\"http://www.diskdepot.co.uk/acatalog/banners/"+banner[num]+"\" border=\"0\" alt=\""+alt[num]+"\" />";
      }
      return(str);
      }
      Then in the header of the webpage to call up the script I would place:
      <SCRIPT type="text/javascript" src="acatalog/script.js"></script>
      And where I want the random image to appear I add:
      <script type="text/javascript">
      document.write(banner());
      </script>
      I have I got it or missing a step? Sorry to do it in detail just want to get it right.

      Thanks Mash
      Mash

      Comment


        #63
        Mash,

        Try it and see. Use Firefox and it's Tools / Error Console for decent diagnostics.

        However use

        <script type="text/javascript" src="script.js"></script>

        As the acatalog will be filled in automatically by Actinic.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #64
          I forgot about Firefox error consoled, my other PC has it coming up at the bottom, running version 3 on this one.

          I do have an error:
          banner is not defined
          document.write(banner());
          The banner is defined I guess in the external file but that is not getting loaded?

          Sadly guessing, any suggestion would be gratefully recieved thanks Mash
          Mash

          Comment


            #65
            Mash,

            Firstly rename that external file to anything but "script.js" - that name may cause problems. Amend your <script type="text/javascript" src="script.js"></script> to use the new filename.

            Make sure that js file is in your Site folder.

            The post an URL of a problem page or we're working blind.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #66
              Hi

              Have now renamed it:

              randomscript.js
              and have set up a test page with just this script in to make it simple for me and easy to upload as that sometimes can be an issue. So the url is Test Page.

              I am currently using the script in the homepage of the site (http://www.organicplants.co.uk/) in a fragment and it works well. So why change it, just want to take out all the script in the header really.

              All the banner images are in the acatalog folder with the script and test page, would like to put the images in a folder and script in a script folder, just tidying away stuff.

              It is generating the alt text and the hypertext but no image, sometimes I have had it turn the whole page in to a link when it has a link.

              Any thoughts, thanks Mash
              Mash

              Comment


                #67
                Check out the properties on the image not working, you can see that it is not looking inside the acatalog folder, fix it so it is and it should be fine.

                Comment


                  #68
                  Have it working but I think the script is missing a '/' when it generates a link so it does not finish the link.

                  I try to add a '/' to it but it does not pick it up.

                  Excellent is working but just that link issue!

                  Any ideas, thanks Mash
                  Mash

                  Comment


                    #69
                    Your logic is wrong. You need to conditionally put the link around the image.

                    Here's what you need (pseudo code)

                    if link {<a href="LINK">}
                    IMAGE
                    if link {</a>}
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment

                    Working...
                    X