Amazon.ca Widgets

How to mix Classic ASP and Server-Side Javascript

Sometimes I need to fix some old Classic ASP applications or add small new features to them.

Because I do Javascript or C# every day for new apps, it hurts to get back to VBScript for these old apps!

That’s why I try to do these using Server-Side Javascript instead.  But wait, how can I mix NodeJS and VBScript?  The answer is, you can’t.  But, there was Server-Side JS before NodeJS exists!

Now, look at this.

You have a ASP Classic site like this:

<body>
<% dim product : product = "apple"
response.write product %>
...

And you need to create a new function to get the product name.

But, you don’t want to do it in VBScript, because you prefer JavaScript.

All you need to do is to create an “include” file, in pure javascript, like this:

includeJS.inc:

function getProduct(){
	var product = "banana";
	return product;
}

And, add it to your existing ASP file:

<script runat="server" language="javascript" src="includeJS.js" ></script>

Finally, you can fix your existing code like this:

<% dim product : product = getProduct()
response.write product %>

Yes, the VB code can call JS function directly.
Also, your JS code can also use already existing VBScript functions and variables.

(edit 2020-12-23) I just added a working sample for this, that you can download, including web.config “urlrewrite” to keep your js-code hidden from browser direct call.

5 thoughts on “How to mix Classic ASP and Server-Side Javascript”

  1. This is cool Frederick but wouldn’t getProduct return the function rather than invoking it? getProduct() would return the result from the function. Also you would no longer need to define product in the ASP page because that is no longer used.

    1. Because the call is from vbscript, so you don’t need to use (). But I think both works. And you are right, I copied the first sample and I forgot to remove the “dim product” ! Thank you.

  2. Thanks for this, very helpful. With regard to Mike Poole’s comment, I found that what he says is correct. The call to getProduct from the asp page needs to be written getProduct(). Without the brackets it just prints the function description.

    1. You are right, I fixed it! I also added a working sample that you can download, with try-catch, just to prove that we can do that from classic asp, plus web.config “urlrewrite” rules, to hide server-side js from direct browser call.

  3. Could you provide more info on
    Also, your JS code can also use already existing VBScript functions and variables.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.