Accessing the host .html file [SOLVED]

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
sylvain
Posts: 4
Joined: Tue Aug 11, 2015 4:23 am

Accessing the host .html file [SOLVED]

Postby sylvain » Tue Aug 11, 2015 4:33 am

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?

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Accessing the host .html file

Postby JS-Support @Userware » Tue Aug 11, 2015 7:07 am

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

sylvain
Posts: 4
Joined: Tue Aug 11, 2015 4:23 am

Re: Accessing the host .html file

Postby sylvain » Wed Aug 12, 2015 6:45 am

Thanks you, that's great!

By the way, is JSIL.Verbatim.Expression(...) a pro or a free feature?

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Accessing the host .html file

Postby JS-Support @Userware » Wed Aug 12, 2015 6:50 am

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.

h82258652
Posts: 12
Joined: Fri Jun 12, 2015 6:23 pm

Re: Accessing the host .html file

Postby h82258652 » Sun Aug 16, 2015 5:02 am

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!! :D


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 49 guests

 

 

cron