Page 1 of 1

Custom HTML Element Attributes [Solved]

Posted: Mon Jul 25, 2016 8:37 pm
by ccreeves
Hello,

First off, thanks so much for your work on this. Can't wait to play with it more.

Is it possible to set a custom attribute on a XAML element at design-time that persists in the output HTML?

For example, I would like to add the attribute "webkit-playsinline" to a MediaElement element so that it appears on the <video> element in the output HTML. Is this possible?

If not, I assume I could manually add this later via Javascript execution...but I notice neither "name" nor "id" attributes are set for html elements at runtime. So how would I go about modifying a specific HTML element?

Thanks,
Chris

Re: Custom HTML Element Attributes

Posted: Mon Jul 25, 2016 9:44 pm
by ccreeves
After further research, I think this is the approach I'd use for manually adding an attribute to a MediaElement (<video>), right?

Code: Select all

                object video = CSHTML5.Interop.GetDiv(MediaElementForVideo);
                CSHTML5.Interop.ExecuteJavaScript("$0.createAttribute('webkit-playsinline')", video);

Re: Custom HTML Element Attributes

Posted: Tue Jul 26, 2016 1:05 am
by JS-Support @Userware
Hi,

Yes, this approach is the correct one.

Please note that the DOM produced by the MediaElement looks like this:

<div>
<video>
</div>

(you can see this by using the developer tools of your browser and inspecting the DOM tree)

Therefore, you should set the attribute on the child of the div, rather than the div itself, like this:

Code: Select all

object video = CSHTML5.Interop.GetDiv(MediaElementForVideo);
CSHTML5.Interop.ExecuteJavaScript("$0.firstChild.createAttribute('webkit-playsinline')", video);


Regards,
JS-Support

Re: Custom HTML Element Attributes

Posted: Tue Jul 26, 2016 7:24 pm
by ccreeves
Makes sense, thanks so much for the reply. :)