Pass return value from html document hosted in iFramePanel

0
0

Hi,

we have a problem figuring out how to call functions in a html-document hosted inside an iFramePanel on a simple wisej-page.
Let’s say we have a html-document with one js-function inside the script element

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″ />
<title></title>
<script type=”text/javascript”>
function multiply(a, b) {
var x = a * b;
alert(x);
return x;
}
</script>
</head>
<body>TEST</body>
</html>

and we want to call it on a button click event outside the iFramePanel where it is hosted and get the result back.

One could think it’s done by calling the Call method of our iFramePanel that is inherited from Wisej.Control, but it always says it cannot find the function.

We’ve tried to use the Eval method with Action<dynamic> callback

void Callback(dynamic input)
{
MessageBox.Show(input);
}

private void button1_Click(object sender, EventArgs e)
{
Action<dynamic> action = Callback;
iFramePanel1.Eval(“iFramePanel1.multiply(2, 3)”, action);
}

and that seems to work only if we specify the call as “iFramePanel1.multiply”, the callback function is being called, but the input parameter is always null.

So we have two questions:
1) How the Call function can be used instead of Eval (we’d like to pass parameters without string conversions and use Action<string> instead of dynamic)?
2) Why the input parameter of our callback is always null?

Regards

Johann

  • You must to post comments
0
0

The iFramePanel control (and widget on the client) is a DIV element that contains an <iframe> element. It’s not the content of the iframe element, which is another document and window domain. Wisej exposes the getWindow() and getDocument() client side methods to retrieve the iframe’s window and document.

You’d have to call the javascript functions using this.getWindow() as the target.

Also, if you use iFramePanel1.Eval) the target is already iFramePanel1. It should be iFramePanel1.Eval(“this.getWindow().multiply(2, 3)”); Assuming that the iframe loads a document with a javascript function “multiply”.

If you want to use Call() instead on the iFramePanel1 control, you need to assign wrapper javascript functions to iFramePanel1. See the JavaScript component. Then you can do this in js (where “this” is iFramePanel1):

this.multiply = function(x, y) {

return this.getWindow().multiply(x,y);

}

And in C#

iFramePanel1.Call (“multiply”, 2, 3, (result) => { … });

or

int result = await iFramePanel1.CallAsync(“multiply”, 2, 3);

 

 

 

 

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.