iLTC Home
Bookmark iLTC!

Categories

Perl
  • Perl Tutorials Beginners

  • Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

  • HTML
  • HTML Tutorials

  • Command Line
  • Command Line Tutorials

  • How Tos
  • Other Tips and Tricks



  • for(var i;i < 1000;i++) { }
    1724586

    iLoveTheCode.com

    Use onClick in Javascript

    There are a couple of ways to use onClick in Javascript...

    You can write the javascript right into the link tag or you can call a function located elsewhere in your code.

    First, we'll write the code right into the link:

    <a href="http://google.com" onClick="window.open('http://google.com');return false">Google</a>

    -After the onClick tag, we enclose our entire javascript code in double quotation marks.
    -We use javascript's built-in window.open method to open Google in a new window. Since we are inside double quotes, we use single quotes around our Google address.
    -We return false so the browser won't use the href tag. If we return true the main browser window would go to the url in the href tag.


    Using onClick to call a function is similar and fairly easy:

    function goGoogle() {
    window.open('http://google.com');
    }

    <a href="http://yahoo.com" onClick="goGoogle();return true">Google</a>

    -First we created our function goGoogle.
    -Instead of writing our code in the onClick tag, we just called our newly created function.
    -This time we returned true so the main browser will go to Yahoo.



    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    function goGoogle() {
    window.open('http://google.com');
    }

    -->
    </script>

    <a href="#" onClick="window.open('http://google.com');return false">Google 1</a>
    <a href="http://yahoo.com" onClick="goGoogle();return true">Google 2</a>



    Resources:
    Create a Function in Javascript
    Call your Function in Javascript
    Opening a REMOTE WINDOW in Javascript




    Previous Article: Increment a Variable in Javascript
    Next Article: Use OnMouseOver in Javascript






    Search iLTC w/ Google




    Recent Articles

  • HTML Font Code
  • Javascript and CSS - Easy Pop Up Help Balloons
  • Use OnMouseOver in Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Renaming a File with Perl's RENAME Function
  • PRINT to Browser with document.write Command in Javascript
  • Passing an Argument or Variable to a Javascript
  • Opening an Alert Box in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • OPEN and WRITE a Data File in Perl
  • OPEN and READ a Data File in Perl
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Javascript Reset Form








  • Perl Programming - Javascript Programming - HTML Code - Mac Unix Command Line - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006-2009 iLoveTheCode.com


    Contact Chris | About this Site


    1724311
    Counter by iLoveTheCode.com


    Last Modified: Thursday, 05-Feb-2009 05:28:29 EST



    Hosted as well :)
    Home-brewed logo - 1997