• Archives

  • Archive for the ‘Javascript’ Category

    Redirecting the user through javascript

    Friday, June 6th, 2008

    Some times we need to redirect the user

    for this we can use javascript

    Syntax:

    <script type="text/javascript">
    <!--
    window.location = "http://www.google.com/"
    //-->
    </script>
    

    You can easily insert this in a javascript function and take out advatage

    thanks

    krates

    Right mouse button was clicked or left ?

    Sunday, June 1st, 2008

    Sometimes you need to know which mouse button has been clicked you can use it block right click on page and many other things

    Syntax:

    <html>
    <head>
    <script type=”text/javascript”>
    function nb(event)
    {
    if (event.button==2)
    {
    alert(“You clicked the right mouse button!”);
    }
    else
    {
    alert(“You clicked the left mouse button!”);
    }
    }
    </script>
    </head>
    <body onmousedown=”nb(event)”>

    Click on the document to know which mouse button was clicked.

    </body>
    </html>

    Check this out by yourself by copying the above code in notepad and save it as .html page

    Thanks

    krates

    Javascript round off

    Tuesday, May 27th, 2008

    Sometimes you need to round off numbers this can be easily done through javascript

    Using Math.round() funtion

    Syntax:

    <html>
    <body>

    <script type=”text/javascript”>

    document.write(Math.round(4.60) + “<br />”);
    document.write(Math.round(2.50) + “<br />”);
    document.write(Math.round(1.49) + “<br />”);
    document.write(Math.round(-5.40) + “<br />”);
    document.write(Math.round(-1.60));

    </script>

    </body>
    </html>

    Thanks

    krates

    Return the length of a string

    Wednesday, May 21st, 2008

    Sometimes you need to get the length in numbers of a string

    you can easily do it by using javascript

    Syntax:

    <html>
    <body>
    <script type=”text/javascript”>
    var text=”Count me!”;
    document.write(text.length);
    </script>
    </body>
    </html>

    Thanks

    krates

    Knowing the screen resolution of the client window

    Tuesday, May 20th, 2008

    Sometimes or many times we need to know the screen resolution of the client window to create webpages according to there resolution !!!

    Syntax:

    <html>
    <body>
    <script type=”text/javascript”>
    document.write(“Screen resolution: “);
    document.write(screen.width + “*” + screen.height);
    document.write(“<br />”);
    document.write(“Available view area: “);
    document.write(screen.availWidth + “*” + screen.availHeight);
    </script>
    </body>
    </html>

    so it is that easy

    thanks

    krates