execScript from C# plugin into javaScript, passing parameters

Add-in Express™ Support Service
That's what is more important than anything else

execScript from C# plugin into javaScript, passing parameters
one way parameters, passed by value? literal? 
Robert Apostolico


Guest


I properly have my C# plugin able to call methods in my javascript code that was injected.

ie. HTMLDocument.parentWindow.execScript("launchInjectedJavascriptCode();");

I was curious though, if its possible to pass parameters into those methods, and if so, how.
If its possible, I'm guessing that it would be a one-way pass by literal.

Let's say my javascript injected method looked like this, with an parameter:


function launchInjectedJavascriptCode(xsParameter) {
    try {
        if ( xsParameter !== null ) {
        // ...
        }
    }
    catch (e) {
    // ...
    }
}


This may sound stupid, but in my C# plugin code, how do I properly pass that parameter?

Would it be similar to this:


//   C# snippet ...

     // this could be a very long, nasty value, perhaps even an html fragment.
     var myParameter = "Hello Javascript";

     HTMLDocument.parentWindow.execScript("launchInjectedJavascriptCode("" + myParameter + "");");



Hopefully I typed my " quotes and \ in the correct spot to essentially word-wrap the value of my parameter with double-quotes within the ( "parens" ).

Would that get passed into the javascript function?
Is there a limitation on the LENGTH of what is concatenated together and passed into execScript?

Thank you!
Posted 10 Jun, 2014 15:56:17 Top
Andrei Smolin


Add-in Express team


Posts: 18827
Joined: 2006-05-11
Robert,

In the manual - see the PDF file in the folder {Add-in Express}\Docs on your development PC - please search for this string "Module-script two-way interaction". This code sample describes how to call a script and assign a variable that the script uses.


Andrei Smolin
Add-in Express Team Leader
Posted 11 Jun, 2014 02:36:57 Top