Search code examples
javascriptwshjscript

How to check if the * .js file is JScript or JavaScript?


I want to use *.js file both: on local web page on my pc (as JavaScript) and as WSH JScript when I double click *.js file. Is it possible to write a code running on both platforms?

How to check is running JS file is JavaScript or Microsoft JScript?

I tried this, but it doesn't work:

if (typeof(document) == "undefined")
    alert('WSH Script!');
    WScript.Quit;
}
else {
    document.writeln('Hello world');
}

Solution

    1. You can check if WScript object exists e.g

      if (typeof WScript === 'object')

    2. Quit is a function so you should call it, e.g

      WScript.Quit();