.NET to JavaScript
Calling JavaScript from .NET is pretty simple. There are two ways of doing that:
- Global JavaScript
- JavaScript Isolation
We will go through both ways to see what the difference is.
Global JavaScript (the old way)
One way is to make the JavaScript method we want to call accessible globally through the JavaScript window, which is kind of a bad practice since it is accessible by all scripts and could replace the functionality in other scripts (if we were to accidentally use the same names).
What we can do is, for example, to use scopes, create an object in the global space, and put our variables and methods on that object so that we lower the risk a bit at least.
Using a scope could look something like this:
window.myscope = {}; window.myscope.methodName = () => { ... }
We create an object with the name myscope
. Then we declare a method on that object called methodName
. In this example, there is no code in the method; this is only...