1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

trouble with Javascript

Discussion in 'Software Development' started by transcriptionist, Nov 11, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. transcriptionist

    transcriptionist Thread Starter

    Joined:
    May 26, 2001
    Messages:
    309
    I am taking a beginner web design class and this week's tutorial is on javascript. The assignment is to change the color of the scrollbar. I am having a heck of a time getting this to work. I am using Alleycode and here is my code - according to the book...

    "<script type="text/javascript">
    <!--Hide from old browsers
    function scrollColor() {
    document.body.style.scrollbarFaceColor="#3300ff"
    document.body.style.scrollbarTrackColor="#3399ff"
    }

    //-->
    </script>"

    The beginning quotations and ending quotations are not in my code. Later in the BODY section I have onload="scrollColor()"

    Can someone tell me why this wont work? I have spent almost the entire day searching for variations in this and I can't seem to find anything that works!

    ((I posted this in the Web Development forum as well))
     
  2. Meyer

    Meyer

    Joined:
    Nov 10, 2007
    Messages:
    8
    Are you allowed to use CSS for this assignment? That is the simplest way to do it, and automatically adjusts for older browsers that won't support the change in scroll bar color. Here is an example that you can paste on the top of your HTML file...

    Code:
    <style>
    <!--
    BODY{scrollbar-face-color:#8080FF;
    scrollbar-arrow-color:#FFFFFF;
    scrollbar-track-color:#DDDDFF;
    scrollbar-shadow-color:'';
    scrollbar-highlight-color:'';
    scrollbar-3dlight-color:'';
    scrollbar-darkshadow-Color:'';
    }
    -->
    </style>
    
    
    Let me know if this works for you... there are JavaScript ways of doing this...

    Hope this helps!
     
  3. transcriptionist

    transcriptionist Thread Starter

    Joined:
    May 26, 2001
    Messages:
    309
    Thank you Meyer - but this is supposed to be in javascript - we worked on style sheets last week.
     
  4. Meyer

    Meyer

    Joined:
    Nov 10, 2007
    Messages:
    8
    OK, sorry about that... CSS is the better way to do it, but this is how to do it in Java Script...

    Code:
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- Begin
    function changeScrollbarColor(C) {
    if (document.all) {
    document.body.style.scrollbarBaseColor = C;
       }
    }
    //  End -->
    </script>
    
    </HEAD>
    
    
    <BODY onload = "changeScrollbarColor('#FF0009');">
    
    
    There is a couple of things to remember with this. Not all browsers support this. I know IE 6.0 and above does. Also, some browsers (even recent ones) will block these kind of functions. You will have to allow for these functions to take place. Usually the webpage will warn you and ask if you want to allow it.

    If you have any more questions, just let me know.

    Thanks!
     
  5. Shadow2531

    Shadow2531

    Joined:
    Apr 30, 2001
    Messages:
    2,636
    This works for me:

    Code:
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Change scrollbar colors in IE with JS</title>
            <style>
                p {
                    width: 2000px;
                    height: 2000px;
                }
            </style>
            <script>
                window.onload = function() {
                    document.documentElement.style.scrollbarFaceColor = "#3300ff";
                    document.documentElement.style.scrollbarTrackColor = "#3399ff";
                };
            </script>
        </head>
        <body>
            <p>test</p>
        </body>
    </html>
    
     
  6. transcriptionist

    transcriptionist Thread Starter

    Joined:
    May 26, 2001
    Messages:
    309
    ah ha! Shadow - that did the trick!! Thank you! :)

    Meyer, thank you for your assistance as well!! ;)
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/650730

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice