Silverlight. js details.

Source: Internet
Author: User

Original article: Understanding the Silverlight. js helper class and Silverlight object Creation

Silverlight. javascript dynamically uses JavaScript scripts to operate the DOM structure of the page. HTML elements are generated at the specified Dom node to call Silverlight ActiveX plugin. Alternatively, HTML elements prompting the installation of Silverlight plugin are generated at this location.

If you want to study Silverlight. js and the Javascript syntax is unfamiliar, this article helps: javascript-defined functions method http://www.wxwdesign.cn/article/skills/269.htm

Microsoft's Silverlight is a browser plug-in, just like Adobe's flash. the Silverlight SDK provides a Silverlight that helps you create a Silverlight object. JS file. when you call a Javascript file, you may find that HTML code is generated when the client has installed Silverlight.

If you want to know what this JS file has done, we need to break it down for research. There are a total of 11 methods in this JS file.

01. Silverlight. detectuseragent ();
02. Silverlight. isinstalled (d );
03. Silverlight. Createobject (L, G, M, J, K, I, H );
04. Silverlight. supporteduseragent ();
05. Silverlight. buildhtml (c, d );
06. Silverlight. default_error_handler (E, B );
07. Silverlight. createobjectex (B );
08. Silverlight. buildprompthtml (L );
09. Silverlight. _ cleanup ();
10. Silverlight. followfwlink ();
11. Silverlight. htmlattributeencode (C );

You may notice that the parameters of these methods are not very clear. this is because Microsoft needs to make JavaScript files as small as possible. so, he removed long names, spaces, line breaks, and so on. This JS file code is all written in line 1. this is not conducive to understanding, but it gives fast loading.

Create a Silverlight object. we can see createsilverlight in the Silverlight 1.0 SDK. JS file. he used the third method Silverlight mentioned above. createobject (L, G, M, J, K, I, H) and the seventh method Silverlight. the seventh method of createobjectex (B) accepts an array of parameters. I think ex is probably an extension.

Looking at the code file and the comment file, we can see what they mean.

L = XAML source file
G = parent hosting Element
M = Silverlight Control ID
J = Properties
K = events
I = initparams
H = Context

This createobjectex method only calls the Createobject method, and there is nothing special.

This Createobject method calls the parameters passed in by createobjectex.

  1. Call the Silverlight. isinstalled (Version) method to determine whether the Silverlight version has been installed. The name of the version is J.
  2. Load the Silverlight. _ cleanup () method to log out windows events
  3. Load the onload and onerror methods. (The parameter is K)
  4. Call the Silverlight. buildhtml (a, B) method to generate the HTML OF THE Silverlight object
  5. If hosting is not empty, add the generated HTML to hosting; otherwise, the generated code is returned.

The last line of code is very interesting. If you want to control the generated HTML, you can pass a null to replace the hosting element to get the generated HTML. if we see the generated HTML, we can find a normal OBJECT tag. if you use safari, you will see an EMBED tag. because safari does not fully support object tags.

This initialization parameter can be selected. You can add custom parameters. it seems a little weird at first, but this JavaScript code is used to generate HTML. this feature is very useful. for example:
Sitename = wpfdevelopment, url = www.wpfdevelopment.com.

The generated HTML code will contain the following parameters:

<Object>
<Param name = "initparams" value = "param1, param2, param3"/>
</Object>

The Safari browser is like this:

<Embed initparams = "param1, param2, param3"/>

This initial parameter is generated by Javascript in the Silverlight object. For example, silverlightcontrolid. initparams returns a list of initial parameters.

The second parameter is the context parameter, which allows event calls. For example, if you have an event that needs to be called in onload:

Events: {onload: onloadfunction}

Function onloadfunction (control, context, rootelement ){
// Do something
}

This event can be used in onload or onerror. You only need to pass it in events (k.

The remaining parameter J is an array. Many attributes can be set.

  1. Background = background color, white by default
  2. Iswindowless = Boolean. Whether transparent
  3. Width = width
  4. Height = height
  5. Ignorebrowserver = ignore whether the Silverlight plug-in has been installed in the current browser. The default value is false.
  6. Maxframerate = maximum number of frames. The default value is 24 frames per second.
  7. Version = Silverlight plug-in version.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.