SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Load stylesheet in Javascript

    Hi

    I have created a web page with a buttons it.
    When user clicks this button (image), I need a new stylesheet to
    load.

    I put this code in the <head> tag....


    <script language="JavaScript">

    delCookie('IncreaseSize');

    function IncreaseFont()
    {
    var sTemp = getCookie('IncreaseSize');
    var the_length = document.cookie.length;
    var iNumber = document.cookie.charAt(the_length-1);
    var iCount = Number(iNumber);
    var sPage = "style_01.css"

    if (sTemp == null)
    {
    iCount = 1;
    setCookie('IncreaseSize', iCount);
    alert("Load stylesheet: " + sPage);
    }
    else if (iCount < 4)
    {
    iCount = iCount+ 1;
    sPage = "style_0" + iCount;
    delCookie('IncreaseSize');
    setCookie('IncreaseSize', iCount);
    alert("Load stylesheet: " + sPage + ".css");
    }
    else
    {
    alert ("Can not increase greater than 4");
    delCookie('IncreaseSize');
    setCookie('IncreaseSize', 4);
    }

    }

    </script>

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give the button an ID and use this code: (putting in it's own script tags just before </body>)

    Code JavaScript:
    document.getElementById('THE-ID').onclick = IncreaseFont
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI

    Here is my button in the web page...
    <img src="magnify_plus.jpg" name="I" onClick="IncreaseFont()" /><br/>

    Here is my code... I'm sorry, I don't get how to do this.


    <script language="JavaScript">

    delCookie('IncreaseSize');

    if (! document.cookie.IncreaseSize)
    {
    setCookie('IncreaseSize', 1);
    }

    function IncreaseFont()
    {
    var sTemp = getCookie('IncreaseSize');
    iCount = Number(sTemp);
    var sPage = "style_0";

    if (iCount < 4)
    {
    iCount = iCount + 1;
    delCookie('IncreaseSize');
    setCookie('IncreaseSize', iCount);

    sPage = sPage + iCount + ".css";
    alert("Load stylesheet: " + sPage);
    return;
    }
    else
    {
    alert("4 is highest");
    delCookie('IncreaseSize');
    setCookie('IncreaseSize', 4);
    return;
    }
    }
    </script>


Bookmarks

Posting Permissions

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