Results 1 to 3 of 3

Thread: javascrip text sizer and colorer

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    364

    javascrip text sizer and colorer

    Hi,
    I am working on a text only version of my website and I am trying to create a javascript that can change the text size - this part works, but i need it to store the info in a cookie so that when you click to go to another page the text is the size you set it, I also need to so that you can change the text colour and the background colour.
    www.christian-kids.net/textonly - have the working text sizer

    thanks
    Richard <><

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    364

    Re: javascrip text sizer and colorer

    so does anyone know how this can be done ?
    Richard <><

  3. #3
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: javascrip text sizer and colorer

    here, i made this code up for you (edit it as needed):
    HTML Code:
    <html>
    
    <head>
    <script type="text/javascript">
    function setCookie(name, value, expires, path, domain, secure)
    {
        document.cookie= name + "=" + escape(value) +
            ((expires) ? "; expires=" : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
    }
    function getCookie(name)
    {
        var dc = document.cookie;
        var prefix = name + "=";
        var begin = dc.indexOf("; " + prefix);
        if (begin == -1)
        {
            begin = dc.indexOf(prefix);
            if (begin != 0) return null;
        }
        else
        {
            begin += 2;
        }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1)
        {
            end = dc.length;
        }
        return unescape(dc.substring(begin + prefix.length, end));
    }
    function deleteCookie(name, path, domain)
    {
        if (getCookie(name))
        {
            document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }
    </script>
    </head>
    
    <body onload="Javascript: if(getCookie('size') && getCookie('color')){document.getElementById('txt').style.color = getCookie('color'); document.getElementById('txt').style.fontSize = getCookie('size');}">
    	<form name="form">
    	size:&nbsp;&nbsp;<input type="size" name="size" size="20" value="20px"><br>
    	color:<input type="text" name="color" size="20" value="blue"><br>
    	<input type="button" onClick="Javascript: document.form('size').value='20px'; document.form('color').value='blue'; deleteCookie('size','',''); deleteCookie('color','','');" value="clear" name="clear">
    	<input type="button" onclick="Javascript: document.getElementById('txt').style.color=document.form('color').value; document.getElementById('txt').style.fontSize=document.form('size').value;" value="apply" name="apply">
    	<input type="button" onclick="Javascript: setCookie('color',document.getElementById('txt').style.color,'','','',''); setCookie('size',document.getElementById('txt').style.fontSize,'','','','')" value="Save" name="save">
    	<br>
    	<br>
    	</form>
    
    <font id="txt">Example</font>
    
    
    </body>
    
    </html>
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

Posting Permissions

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



Click Here to Expand Forum to Full Width