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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change font sizes

    I have a script to make font sizes larger/smaller when a user clicks on an icon. Is it possible to make it so not only <p> tags are made larger/smaller, but ALL font on the page?

    Here is the script I have:

    Code:
    <script type='text/javascript' language='javascript'>
    var min=8;
    var max=24;
    function increaseFontSize() {
       var p = document.getElementsByTagName('p');
       for(i=0;i<p.length;i++) {
          if(p[i].style.fontSize) {
             var s = parseInt(p[i].style.fontSize.replace("px",""));
          } else {
             var s = 16;
          }
          if(s!=max) {
             s += 1;
          }
          p[i].style.fontSize = s+"px"
       }
    }
    function decreaseFontSize() {
       var p = document.getElementsByTagName('p');
       for(i=0;i<p.length;i++) {
          if(p[i].style.fontSize) {
             var s = parseInt(p[i].style.fontSize.replace("px",""));
          } else {
             var s = 16;
          }
          if(s!=min) {
             s -= 1;
          }
          p[i].style.fontSize = s+"px"
       }   
    }
    </script>

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think that better solution of resizing font size is store selected font size in the cookie, and then include the external CSS definition file based on the value stored in cookie.

    e.g:
    Code:
    <?php if ($_COOKIE['fontsize']=='small')
    echo '<link rel="stylesheet" type="text/css" href="small.css">'; ?>
    etc..
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do you mean? I am totally new at this coding thing.

  • #4
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I mean.. is it absolutely necessary use javascript to resize fonts? Because, when user refresh the page, selected font size will be default again.. So you need to use some server side solution like cookie and CSS file, I think..
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php


  •  

    Posting Permissions

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