#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    26
    Rep Power
    0

    Question changing fontsize with javascript


    how can i change the fontsize of the browser with an javascript (with an "+" & "-" button for example)?

    i was asked for this for an fullscreen websize (as the IE menu isnīt visible).
    i have search the net already but found only a pay-script.

    thanks in advance,
    Mikk
  2. #2
  3. Digitally Challenged
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    280
    Rep Power
    12
    here is one idea. have a style assigned to your <body> tag. then have the + and - be links or buttons. have an onclick event that changes a url variable that represents the size that is also linked to the style for the body. don't know if that helps, but give it a shot.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    26
    Rep Power
    0
    iīm not very good with java so iīm not shure if i understand correctly.

    you mean i shall put the fontsize into an variable which i manipulate via onclick (?)

    but why should the fontsize change only because of the changing variable? wouldnīt i have to tell the browser that he has to rewrite the text with the new fontsize?

    i have seen a working example online already in which it worked on-the-fly. just one click and the textsize changed, without refreshing the site.
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    Code:
    <html>
    
    <head>
    <title>Change Font Size</title>
    <script language="javascript">
    function changeFontSize(num)
      {
      document.body.style.fontSize = (parseInt(document.body.style.fontSize) + num).toString() + 'pt';
      }
    </script>
    </head>
    
    <body style="font-size:12pt">
    <p>This is some font to change the size of!</p>
    <form>
    <input type="button" value="Smaller" onclick="changeFontSize(-2);">
    <input type="button" value="Larger" onclick="changeFontSize(2);">
    </form>
    </body>
    
    </html>
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    26
    Rep Power
    0
    thank you!
    works perfect.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    26
    Rep Power
    0
    i just tried to put this code into my site and have stumbled about an small problem.

    as i have to place the code (+images to click on) into an frame (top) i have noticed that the textsize changes only in the top frame when executed.
    is there a way to enhance the script so that the textsize will change on the whole page (all frames) ?

    thanks in advance,
    mikk
  12. #7
  13. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    I don't use frames os I have no experience using JavaScript accross frames, but you can give this a try:
    Code:
    <script language="javascript">
    function changeFontSize(num)
      {
      for(i=0; i<window.frames.length; i++)
        {
        window.frames[i].body.style.fontSize = (parseInt(window.frames[i].body.style.fontSize) + num).toString() + 'pt';
        }
      }
    </script>
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    26
    Rep Power
    0
    this script isnīt doing anything to me.
    itīs neither giving an error message nor changing the fontsize in any frame.

    perhaps you can tell me how to make the script working for one special frame (all frames is not that important, as i have top,left frame which are not affected by fontsizes anyway (as they have no text).
    only my main frame needs to be affected by the script, but the script has to be called from the top frame.

IMN logo majestic logo threadwatch logo seochat tools logo