Page 1 of 1
Accessing the host .html file [SOLVED]
Posted: Tue Aug 11, 2015 4:33 am
by sylvain
Hi.
I'm searching for a way to access the hosting .html file. I'd like to get the content of a div that I place just after <div id="log"> in the generated index.html file.
Of course I could use WebClient to do that. But that would make a second http request for the same file.
Is there any other way?
I noticed that if I call
object div = CSharpXamlForHtml5.DomManagement.GetDomElementFromControl(MainPage);
I get the hosting div.
Any way to get its neighbor div?
Re: Accessing the host .html file
Posted: Tue Aug 11, 2015 7:07 am
by JS-Support @Userware
Hi Sylvain and welcome to the forums,
There are many ways to access the div.
One of them is to use the powerful "JSIL.Verbatim.Expression" method that lets you insert raw javascript code anywhere in your C# code.
Here is an example:
Code: Select all
if (CSharpXamlForHtml5.Environment.IsRunningInJavaScript)
{
string elementId = "INTERNAL_RootElement"; //todo: Replace with the ID of the DIV that you want to access.
dynamic div = JSIL.Verbatim.Expression("document.getElementById($0)", elementId);
string textToDisplay = "The ID is: " + (string)div.id;
MessageBox.Show(textToDisplay);
}
else
{
MessageBox.Show(@"""JSIL.Verbatim.Expression"" is not supported when running in the simulator.");
}
Full documentation for the JSIL.Verbatim.Expression feature will be released with the Beta 5 in the coming weeks.
Regards,
JS-Support
Re: Accessing the host .html file
Posted: Wed Aug 12, 2015 6:45 am
by sylvain
Thanks you, that's great!
By the way, is JSIL.Verbatim.Expression(...) a pro or a free feature?
Re: Accessing the host .html file
Posted: Wed Aug 12, 2015 6:50 am
by JS-Support @Userware
Thanks. It is a Pro feature. On the website it is currently written "Coming soon: Extensibility: embed JavaScript in C#, embed HTML in XAML" under the "Pro" section, but it will be made more obvious in a future beta when the feature will be fully supported.
Re: Accessing the host .html file
Posted: Sun Aug 16, 2015 5:02 am
by h82258652
JS-Support wrote:Thanks. It is a Pro feature. On the website it is currently written "Coming soon: Extensibility: embed JavaScript in C#, embed HTML in XAML" under the "Pro" section, but it will be made more obvious in a future beta when the feature will be fully supported.
Thanks team's work!! Waiting beta5!! I am very exciting!!
