Injecting embedded resources

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

Injecting embedded resources
 
Ben Cowling




Posts: 18
Joined: 2010-10-25
Hi

I am trying to inject a javascript file that links to a couple of images and a CSS file. I can see how I can inject a new script tag but I don't know what to use for the src attribute. I can copy the relevant files to the temp internet folder but how do I reference them from there?

Regards

Ben
Posted 03 Jan, 2013 05:16:03 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Ben,

You don't need 'src'. You can inject the script as a text.
E.g.


      string scriptText = "var my_var = null;";
      mshtml.IHTMLScriptElement scriptObject =
           (mshtml.IHTMLScriptElement)HTMLDocument.createElement("script");
      scriptObject.type = @"text/javascript";
      scriptObject.text = "
" + scriptText + "
";
      ((mshtml.HTMLBody)HTMLDocument.body).appendChild((mshtml.IHTMLDOMNode)scriptObject);
Posted 03 Jan, 2013 05:41:14 Top
Ben Cowling




Posts: 18
Joined: 2010-10-25
How can I reference images, style sheets etc?
Posted 03 Jan, 2013 09:30:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Ben,

You can add the custom CSS using the createStyleSheet function:

mshtml.IHTMLStyleSheet styleSheet = HTMLDocument.createStyleSheet("", 0);
styleSheet.cssText = MyResources.my_css;

As to images, you can embed them in the binary format.
E.g.
<img src="data:image/png;base64,<array of bytes>" class="my_class" rel="<unique ID" title="<my title>" />
Posted 04 Jan, 2013 03:36:51 Top
Ben Cowling




Posts: 18
Joined: 2010-10-25
Thanks, that works great.
Posted 08 Jan, 2013 04:07:17 Top