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.
- Call the Silverlight. isinstalled (Version) method to determine whether the Silverlight version has been installed. The name of the version is J.
- Load the Silverlight. _ cleanup () method to log out windows events
- Load the onload and onerror methods. (The parameter is K)
- Call the Silverlight. buildhtml (a, B) method to generate the HTML OF THE Silverlight object
- 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.
- Background = background color, white by default
- Iswindowless = Boolean. Whether transparent
- Width = width
- Height = height
- Ignorebrowserver = ignore whether the Silverlight plug-in has been installed in the current browser. The default value is false.
- Maxframerate = maximum number of frames. The default value is 24 frames per second.
- Version = Silverlight plug-in version.