The making of TSW WebCoder 2013 part 7 – Scripting with JavaScript

August 30, 2012

You have been able to extend the functionality of WebCoder with scripting for many versions, first with a Pascal syntax and later with a Python syntax, because IronPython worked so well with .NET. For WebCoder 2012 I would like to offer you something a bit closer to the Web-world though: Scripting with JavaScript syntax. Since a lot of you are already using JavaScript for your websites, I hope that this will make the scripting functionality useful to even more people.

As you can see from the following (admittedly silly) example, scripting will be a nice mix of JavaScript syntax and the .NET class library, combined with the useful classes used from WebCoder it self:

var tag = new TSW.WebCoder.Classes.Html.HtmlTag();
tag.Name = "div";

var sb = new System.Text.StringBuilder();
for(var i = 0; i < 3; i++)
	var rnd = Math.floor((Math.random() * 10) + 1);
	tag.SetAttribute("class", "test" + rnd);
	sb.Append(tag.GetMarkup(false) + "\n");


We use the HtmlTag class from WebCoder to create a new HTML tag, we use the .NET StringBuilder class to hold the tags, we use the Math class and its floor() and random() methods for obtaining a random number between 1 and 10, and we use a regular JavaScript loop to add the tags to the StringBuilder. The alert() method is normally a part of the browser DOM and not core JavaScript, but has been implemented in WebCoder to make it easy for everyone to show a message box, just like in the browser. Here's the result when running the script:


Stay tuned for the next part, where I will show you some more cool stuff from the new scripting functionality in WebCoder 2012. I hope you like what you've seen so far. Let me know what you think :)

Kasper (TSW) @ 11:41 am in TSW,WebCoder

One Response to “The making of TSW WebCoder 2013 part 7 – Scripting with JavaScript”

  1. […] (typeof(addthis_share) == "undefined"){ addthis_share = [];}In the previous blog post we talked about the new scripting support with JavaScript syntax, which allows you to extend the […]

Leave a Reply