Debugging JavaScript Functions Through Console

In this post we will show how to debug JavaScript through the developer console. We will do this example in Chrome, and it works in similar ways for other browsers. Consider the example where we have an HTML file with an embedded JavaScript function called HelloWorld(): Running this simply produces an alert: Now let’s open the debugger by pressing F12, and put a breakpoint on the code at line 6: … Continue reading Debugging JavaScript Functions Through Console

JavaScript – Scroll to Top

In a scenario where we need to scroll to the top of a web page, we can use JavaScript’s scrollTo. Consider the scenario where there is a page filled with text, and the scroll bar appears. With a scroll button at the bottom: We can add the following code to set the window to it’s x/y coordinates: window.scrollTo(0,0); Full code: When clicking the button, the page will scroll to the … Continue reading JavaScript – Scroll to Top

JavaScript Async / Await

In some previous posts, we looked at using callbacks and promises. In this post, we will look at Await / Async in JavaScript. Await / Async is built on promises, and is a clean way to represent asynchronous processes in a synchronous way. For example, consider the code below. We have 2 functions, DoSomethingAsync and DoSomethingElseAsync.  The first function will complete in 2 seconds, and the second function in 1 second: If … Continue reading JavaScript Async / Await

Dynamics CRM Creating and Debugging JavaScript Code

One of the benefits of using Dynamics CRM is the ability to write client side JavaScript code to perform actions on the user interface. Let’s go through an example of how to do this. In this example, we will show a message box when a user changes a value on a field. We will do this on the Website field on the Accounts form: Firstly, edit the Accounts form to display the developer view: … Continue reading Dynamics CRM Creating and Debugging JavaScript Code

Node.js Hello World on Windows

In this example, we will create a Hello World application for Node.js. Let’s start with a simple example. I have installed Node.js on Windows and have a Node directory in C:\ drive. In command prompt, cd to this directory. In that directory is a JavaScript file that writes out a console log “Hello World”: To run the file, enter: node HelloWorld.js Hello World is returned by Node. Now create a new … Continue reading Node.js Hello World on Windows

D3 Hello World

To create a D3 “Hello World”, do the following. Go to the website and find the latest D3 version: Copy the link to the latest release: <script src=””></script> Create an HTML page and add the following code, with the link above: <!DOCTYPE html> <meta charset=”utf-8″> <body> <script src=””></script> <script>“body”).append(“span”) .text(“Hello world”); </script> Run the page:  

Dynamics 365 $ is not defined

In your JavaScript code, you may receive this error when running jQuery code: $ is not defined To resolve this, add the following code to JavaScript before the jQuery call is made: if (typeof($) === ‘undefined’) { $ = parent.$; jQuery = parent.jQuery; }