Centering a Javascript text

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • sandysewin
    Master Sergeant

    • Feb 2006
    • 67

    Centering a Javascript text

    I've added a bit of Javascript to my "tips" page to have a tip of the day. I've got a decent understanding of HTML but don't know much about Javascript.

    All I want to do is center some of the shorter tips. If I have to center them all, that's ok, too. I'm sure it's a very simple fix, hope someone can help me.

    Thanks,

    Sandy
    www.creationspraise.com
    www.secretsoforganizedpeople.com
    www.huntresscustom.com

    The one who dies with the most toys wins . . . . . . . . nothing! (Matthew 16:26)
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: Centering a Javascript text

    If there is html code that goes along with the javascript

    like either

    <a onclick="javascript_function()" href="http://somewhere.com">Link</a>

    Or

    <div onload="function()"></div>

    Then just surround whatever html tags go with the javascript with <center></center>

    If everything is contained within the javascript code (IE. the javascript outputs or spits out the html for whatever it is doing), then you will need to do some editing to the html it spits out. The easiest is again surrounding it with <center></center>

    And just for clarity, I DO NOT mean doing something like this

    <center>
    <script>
    javafunction() {
    // whatever it does
    }
    </script>
    </center>

    This will do anything, it has to be done to the html thats controlled by the javascript.


    If you need help just post all the code related to the javascript

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • Jeremy
      Brigadier General

      • Apr 2006
      • 1502

      #3
      Re: Centering a Javascript text

      Place this in the script:

      // Get the size of the screen
      Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

      // Determine the new location of the window
      int w = window.getSize().width;
      int h = window.getSize().height;
      int x = (dim.width-w)/2;
      int y = (dim.height-h)/2;

      // Move the window
      window.setLocation(x, y);
      Best regards,
      Jeremy

      www.cornwall4rent.com

      Comment

      • sandysewin
        Master Sergeant

        • Feb 2006
        • 67

        #4
        Re: Centering a Javascript text

        That looks awesome, Jeremy, but I'm not sure where to put it. I tried a couple of spots, but neither worked and I'm really just flailing around blindly. ***grin***

        Here's the tips script:

        <script language="JavaScript">
        /*Tip Of The Day Script
        Created By MikeW at mikew@dvol.com. Copyright 2000 by MikeW - Please leave all credits in place if useing this script. Featured on A1 javaScripts, www.a1javascripts.com */
        //Make new array and get the current day in var today
        var msg = new Array();
        Stamp = new Date();
        today = Stamp.getDate();
        //put the tip of the day in each msg[x] string
        //change tips each month, automatically switches every day
        msg[0]="Tip 1"
        msg[1]="Tip 2"
        msg[2]="Tip 3"
        msg[3]="Tip 4"
        msg[4]="Tip 5"
        msg[5]="Tip 6"
        msg[6]="Tip 7"
        msg[7]="Good judgment comes from experience, and a lot of that comes from bad judgment. - Will Rogers"
        msg[8]="When adding built-ins to a room, it isn't always necessary to exactly match the existing hardware. If you choose knobs & handles with the same type of metal, a similar style or a similar finish, it will work."
        msg[9]="If you find yourself in a hole, stop digging. -Will Rogers"
        msg[10]="Keep in mind that less expensive products are not always a bargain. A cheaper item may be more difficult for your builder to install, thus adding to the labor charges. Quality products are worth the extra expense because they operate more smoothly, break down less often and frequently have longer warranties."
        msg[11]="Difficulties mastered are opportunities won. - Winston Churchill"
        msg[12]="When you are thinking about a project, start a file folder and add to it clippings, magazine photos, paint chips, sketches of your ideas, etc. This will clarify what it is you want, and help your builder understand your needs."
        msg[13]="Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety. -Benjamin Franklin"
        msg[14]="Ask potential builders what they use in their cabinetry. The answer should be furniture grade plywood (no particle board.)"
        msg[15]="Live in such a way that you would not be ashamed to sell your parrot to the town gossip. -Will Rogers"
        msg[16]="If your project will include drawers, full extension under-mount draw slides are the BEST! No more digging to get at the lost items in the back."
        msg[17]="Regardless of the materials and style you choose, proportion and scale are what will make your project 'work' in your space. You should consider the scale of the room, other furnishings already present, as well as the proportions of the trims and hardware."
        msg[18]="Some places to collect design inspiration: library books, magazines, catalogs, historic buildings, television shows, movies."
        msg[19]="Bring a digital camera with you wherever you go. Use it to snap shots of details or designs you like."
        msg[20]="Bring a digital camera with you when shopping for hardware or other details. Being able to carefully consider your choices at home will make the process easier."
        msg[21]="Carefully consider the use of your completed project. If you will be using it for storage, a file cabinet or bookcase for example, gather together all the items you will be storing. This will give a realistic idea of how much space you need. Consider future needs as well."
        msg[22]="Bookcases often look cluttered when filled with an assortment of books. To make them more interesting, add some small family photos, momentos and objects that you enjoy."
        msg[23]="Tip 24"
        msg[24]="Tip 25"
        msg[25]="Tip 26"
        msg[26]="Tip 27"
        msg[27]="Tip 28"
        msg[28]="Tip 29"
        msg[29]="Tip 30"
        msg[30]="Tip 31"
        //write todays tip so that the tip number matches with the day
        document.write(msg[today-1]);
        </script>

        Thank you both for your lightning FAST responses.

        Sandy

        P.S. Yup, sorry about posting twice. I realized I'd posted the first time in the wrong forum. Thought I could delete the duplicate, but couldn't.
        www.creationspraise.com
        www.secretsoforganizedpeople.com
        www.huntresscustom.com

        The one who dies with the most toys wins . . . . . . . . nothing! (Matthew 16:26)

        Comment

        • Watdaflip
          Major General

          • Sep 2005
          • 2116

          #5
          Re: Centering a Javascript text

          The second last line, try this

          document.write("<center>"+msg[today-1]+"</center>");

          Register/Login Script
          Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

          Comment

          • sandysewin
            Master Sergeant

            • Feb 2006
            • 67

            #6
            Re: Centering a Javascript text

            Ah-ha! Works like a charm. Too cool, many thanks!
            www.creationspraise.com
            www.secretsoforganizedpeople.com
            www.huntresscustom.com

            The one who dies with the most toys wins . . . . . . . . nothing! (Matthew 16:26)

            Comment

            • Jeremy
              Brigadier General

              • Apr 2006
              • 1502

              #7
              Re: Centering a Javascript text

              Haha, glad to know its working now!
              Best regards,
              Jeremy

              www.cornwall4rent.com

              Comment

              Working...
              X