Javascript Stock Ticker

Javascript Stock Ticker

Installing a javascript stock ticker on your website is a fast and easy way to put dynamic content on any page. Add in the ability to configure it to your user's needs and it becomes one of the most useful pieces of coding to know.

Finding the Right Code

Javascript is one of the first methods ever used to extend the functionality of the web beyond HTML. As a result, many variations of the javascript stock ticker now exist on the web. A simple Google search will bring up hundreds of examples - but then comes the question of which stock ticker is right for you? Consider the following factors:

  • Is your website graphics-intensive or text-based? A simple one-line ticker will fit better into the latter, but a complex NASDAQ-style widget might be better for the splashy pictures.
  • Do you need to show all stocks, current stocks, or a trend of a certain stock over time? Various kinds of javascripts can do all of these things, but you need to pick the right one.
  • What is your level of coding expertise? All stock tickers require some element of going "under the hood" of your web code and configuring the javascript. How much you feel comfortable doing will determine which one you choose.
  • Is there support? Related to the previous point, is there a wide user base or other support network for the javascript you chose? Because there have been so many tickers created, some of them will not be more than a snippet of code on an outdated web page.

If you're not sure what code to get, the best way to decide is to find an example of one you like and either view the source code or contact the site administrator and ask them which one they used. Look for reviews and comments by people who have used them in the past, and that will give you the basis of an informed decision.

Integrating a Javascript Stock Ticker

While there are many variations on a stock ticker, they all share one common element: Javascript. There are some specific techniques to implementing javascript that are common to all web pages.

On or Off the Page

You can include the javascript on the web page itself, but that's not the most efficient way to do it. It makes more sense to store the code in an independent file (called something like "stockticker.js") and then include a call to that file on any web page where you want to show it. That way, if you ever want to update or change the stock ticker, you simply change the "stockticker.js" file and all your pages reflect the change. To include a call to a .js file, you need to put a tag into the HEAD section of your web page, something like this:

<script language="javascript" type="text/javascript" src="stock-ticker.js"></script>

Otherwise you would call the javascript language and then include the code within <!--> tags. This is a way to let non-javascript-enabled browsers to skip over the resulting code. It should be noted that if your users do not have javascript enabled, your ticker will not work - but there is nothing you can do about that, and most users want the functionality. There are also stock tickers that use other methods, such as CSS or RSS, to incorporate the functionality of javascript without requiring a javascript call.

Inserting Into HTML

Once the .js code is set and configured (following the developer's directions) the next step is to insert the ticker into the place in the HTML where you want it to show. There are a variety of ways to do this - again, the script developer will most likely have very clear instructions as to how to insert the code into your page.

<script type="text/javascript" src="stockticker.js" language="javascript"></script>

To learn more about creating and configuring your own javascript stock ticker, read the many Javascript programming articles offered here at LoveToKnow.

Javascript Stock Ticker