Introduction

The ChemDoodle Web Components library is a Javascript library and runs in the browser. To begin, please download and install ChemDoodle Web Components. The rest of this page will cover some introductory material.

We will not cover the basics of Javascript here, but the following resources will provide more instruction:

Hello ChemDoodle!

To start, let’s just write a simple script that displays a popup with the current version of the ChemDoodle Web Components library installed. To use Javascript in HTML web pages, all code must be encapsulated in <script> tags. We will use a function called alert() to popup the message “Hello ChemDoodle!”. Write the function as follows in the <body> tag of your HTML file:

1
2
3
4
<script>
  var message = 'Hello ChemDoodle!';
  alert(message);
</script>

Run

 
When you load your webpage in a browser, the message “Hello ChemDoodle!” should appear. You can click on the Run button above to see this in action right now. Now that you can see the message, let’s see how to access the ChemDoodle Web Components library.

When you link the ChemDoodleWeb.js file as a URI resource in your webpage, a single variable, ChemDoodle, is placed into the global Javascript namespace for that page. All functions in this library can be accessed through this single ChemDoodle variable. So let’s just make sure that ChemDoodle Web Components was properly installed by viewing its version. We can obtain the version by calling the ChemDoodle.getVersion() function. So let’s modify our script to display this as follows:

1
2
3
4
<script>
  var message = 'The version of ChemDoodle installed is: '+ChemDoodle.getVersion();
  alert(message);
</script>

Run

 
Again, reload the page and the new message with the version number of the library will be displayed. You can click on the Run button above to see this behavior now. If you do not see the message or the version number, then an error has occured. Your browser of choice has Javascript developer tools to help you with debugging.

Debugging Javascript

Every programmer will have to debug code at some point. Unfortunately, the debugging process for Javascript is a bit more cryptic than for other programming languages. Every major browser has tools and strengths for Javascript development. Our team prefers to debug Javascript in Google Chrome. The following lists a few Javascript debugging resources:

Continue to Loading Data →