6

I am using InstallShield Express to create a setup project.

I try to add a custom action for Uninstallation, before "System Changes".

The custom action is a JavaScript which will open a window, as below:

window.open("https://www.example.com/", "_blank");

However, when I try to uninstall the program, I get an error said "Microsoft JScript Runtime Error, 'window' is not defined.

Why?

Update:

Finally I choose to use a MSI DLL instead of the script to solve the problem. What should I do with this question? THanks.

alancc
  • 487
  • 2
  • 24
  • 68
  • 4
    i don't know what install shield is, but whatever environment this code is running in isn't a browser. as window is an object provided by browsers, referring to the actual browser window it's running in, and as such, is only available in browser environments – bryan60 Apr 25 '20 at 04:41
  • Try to create an action script with `LaunchAppAndWait("explorer.exe", "https://www.example.com/", WAIT)`. Check this Q/A ["how to open a web page on click of button in InstallShield?"](https://stackoverflow.com/questions/1809204/how-to-open-a-web-page-on-click-of-button-in-installshield). – Christos Lytras Apr 25 '20 at 15:36
  • nitpick: The custom action is _JScript_, not _JavaScript_. Slightly different dialects of ECMAScript. – Wyck May 01 '20 at 18:24

1 Answers1

2

The windows object does not exist in NodeJS. However, if you just want to declare a global variable to use it later, you can add the open method in the global object like:

glboal.open = function whatever(url, param2){

// does the stuff you want

};

And then you can use it this way:

conosle.log(global.open('https://www.example.com/','_blank')); 

But i still do not recommend creating a global variable for this. Make a function in a file and import it when you need it. Global variables can cause coupling, and make code harder to read. Also, this variable will exist the entire lifetime of the application, and this might not be good if you are going to make more of them.

If you want to read more about why global variables are bad: https://wiki.c2.com/?GlobalVariablesAreBad