my test.html content is as follow:
<html xmlns=”http://www.w3.org/1999/xhtml”><head><title>Launch Custom URL </title>
<script type=”text/javascript”>function LaunchURLScript(){var url = “RGBHexColorPicker:”;window.open(url);self.focus();}
</script></head><body style= “background-color:#D7D7D7″>
<input type=”submit” name=”Launch” id=”Launch” value=”Launch Custom URL” onClick=”LaunchURLScript()” /> </body></html>
Q1: How to setting above Javascript function LaunchURLScript() in Wesej.Web Web Page Page10.cs ?
Q2: How to use Application.Call(“LaunchURLScript”) in Wesej.Web Web Page Page10.cs OnLoad() ?
If your javascript code is very simple, there’s an easier way to do this: you can just use Eval instead of Call. You will just put the entire contents of the function inside of Eval, like so:
Eval("javascript code here");
Here’s the documentation on using javascript in Wisej, you will find this helpful:
https://docs.wisej.com/docs/concepts/javascript
Note that it’s not enough to just create a .js file, like startup.js and put it in the solution.
There’s some extra steps to get the C# code (in this case CKEditor.cs) to access it:
1.
startup.js is an embedded resource. If you click on starup.js and look at the file properties, you will notice the build action is set to “embedded resource” (see screenshot)
2.
Look at this code from CKEditor.cs:
private string BuildInitScript()
{
IWisejControl me = this;
dynamic options = new DynamicObject();
string script = GetResourceString("Wisej.Web.Ext.CKEditor.JavaScript.startup.js");
options.config = this.Options;
options.fonts = this.FontNames;
options.basePath = CKEditor.BaseUrl;
options.showFooter = this.ShowFooter;
options.showToolbar = this.ShowToolbar;
options.externalPlugins = this.ExternalPlugins;
script = script.Replace("$options", options.ToString());
return script;
}
Specifically, we care about this line: string script = GetResourceString("Wisej.Web.Ext.CKEditor.JavaScript.startup.js");
This reads the contents of the file as a string from the embedded resource.
Note that some widgets like the CKEditor also rely on packages, those are the JS core packages of the component itself.
For example this cdn: https://cdn.ckeditor.com/4.12.1/full-all/
If you look at the Wisej extensions, which are open source on github, you can see some examples which are similar to what you are trying to do.
For example, if we look at the CKEditor code: https://github.com/iceteagroup/wisej-extensions/tree/3.2/Wisej.Web.Ext.CKEditor
From CKEditor.cs:
public bool ReadOnly
{
get { return this._readOnly; }
set
{
if (this._readOnly != value)
{
this._readOnly = value;
Call("setReadOnly", value);
}
}
}
private bool _readOnly = false;
You’ll notice it is calling the function setReadOnly
and sending in the parameter value
The javascript code is located in the file startup.js, and looks like this:
// applies the read only state.
this.setReadOnly = function (value) {
try {
if (this.editor.readOnly != value)
this.editor.setReadOnly(value);
} catch (e) { }
}
So, instead of embedding your javascript in HTML, it should be in a .js file.
Please login first to submit.