I have a WiseJ application, ported from VWG. One of the pages contains an HtmlBox. At runtime, the code-behind calls a service which returns some HTML (don’t get me started on what a bad design this is – not my doing). The returned HTML contains markup and script using JQuery.
The HTML is displayed, but there’s no sign of life from the JQuery application.
The HTML script tags look like this:
<script type=’text/javascript’ src=’INSTPATH/js/jquery/jquery.min.js’></script>
Where INSTPATH is replaced at runtime with text that I can control. I’ve put the necessary files in a JS sub-folder of my application directory, yet I can’t see that the browser is even attempting to read these files.
So, I guess there are two questions, really –
I know this is a basic question – but I’m fundamentally not a web developer, and the things I can think of to try haven’t worked, so here I am.
1. For your question of “Should this work?”- No, there are security restrictions preventing it from working. This is by design- think of the HtmlPanel as being in a sandbox, isolated from the main app. However, there is a workaround where you can use the InitScript property to execute the JavaScript- see this forum post for an example: https://wisej.com/support/question/using-html-in-an-html-panel
2. Regarding the IFramePanel, you are correct in that you would need to supply a URL to use the IFramePanel. I wouldn’t recommend using the IFramePanel for this anyways, as it will be subject to CORS restrictions. You can execute javascript code in the IFramePanel, but there will be some difficulty in getting it to interact with the main app. You would need to implement a way to send and receive messages using the postMessage() APIs.
3. Re: Where should I put the .js files and how should they be referenced in the HTML?
You have several options for running JavaScript code in Wisej:
1. As I mentioned earlier, you can use the HtmlPanel and do something similar to https://wisej.com/support/question/using-html-in-an-html-panel. That example loads javascript from a cdn (the ChartJS library) but it should also work when loading javascript from a filepath.
2. You can use the Widget class, see: https://docs.wisej.com/docs/controls/content/widget and https://docs.wisej.com/api/wisej.web/content/widget
We use this to integrate third-party JavaScript applications, but you can use it to run your JavaScript code. If your put your javascript code in the InitScript, it will run when the widget is created. Alternatively, if you want to keep your javascript code in a separate file, you can reference that file using the “Packages” property, which can be set in the designer. Once you have added a package, for the “Source” simply put the relative filepath to your script. You can then call whatever javascript methods you need from your code in the InitScript. I recommend this method, as it integrates the most closely into the rest of the application.
3. You can use the JavaScript Extender. Simply search for “JavaScript” in the Toolbox, then drag and drop the extender into the designer.
see https://docs.wisej.com/docs/concepts/javascript and https://docs.wisej.com/api/wisej.web/extenders/javascript
You may find the SetJavaScriptSource function helpful as it lets you load JavaScript from a file: https://docs.wisej.com/api/wisej.web/extenders/javascript#setjavascript-control-script
4. You can use the Call and Eval functions to call JavaScript code from your C# code.
https://docs.wisej.com/api/wisej.web/general/control#call-function-args
https://docs.wisej.com/api/wisej.web/general/control#eval-javascript
https://docs.wisej.com/docs/concepts/javascript has some code examples that use Call and Eval.
Hope this helps!
-Julie
Since apparently the folks at WiseJ don’t get notified about comments, I’ll post this as an “answer”. I strongly suspect that this is the culprit:
The VWG component “HtmlBox” is implemented as an <iframe>, while the WiseJ “HtmlPanel” is implemented as a <div>. So, the question becomes, is there a control in WiseJ that wraps an <iframe> and if not, what does it take to make one?
Or am I wrong?
I see that there is an IFramePanel component, but it only accepts a URL – I need to supply the content to the control as HTML, not via a URL…
Hey Carl,
Can you please attach a small runnable sample project that demonstrates what you’ve mentioned?
Thanks,
Levie
Please login first to submit.