By default, the generated page code may look like the following:
I personally feel that this user experience is not very good. Just imagine, if there are multiple Silverlight plug-ins on the current page, wouldn't multiple prompt boxes pop up? So how to solve this problem? In fact, in addition to adding object tags directly on the page to render Silverlight, we can also dynamically add Silverlight through javascript scripts. The Silverlight.js script provides us with a series of available methods. For details, you can refer to msdn http://msdn.microsoft.com/zh-cn/library/cc838126(v=VS.95).aspx #isinstalled
And how to add Silverlight to the page through script, http://msdn.microsoft.com/zh-cn/library/cc265155(v=VS.95).aspx
msdn gives very detailed examples to tell us how to use these script methods. One thing to note is that when using the Silverlight.js file, it must be consistent with the current Silverlight version, otherwise there may be script errors. The corresponding The Silverlight.js file can be downloaded from Microsoft's website. You will find that there are actually many versions available, including versions that support debugging.
There are several issues that need to be paid attention to when using the createObject method parameters:
1. Parameters are specified in order. If there are parameters that do not need to be passed, they can be replaced by null.
2. The parent element parameter must be specified, which is the parent element of the object tag. You can directly pass the element's id as an object, but it is not supported in Firefox. In this case, you can use the document.getElementById('elementId') statement. Just replace this parameter.
3. The param list is passed through an array, and the parameter name can be consistent with the name used in the object tag.
4. If the event list does not have a corresponding page script, a null value will be passed, otherwise a script error will be reported.
5. The last parameter context can be omitted if it is not needed. There is no need to pass null or empty value.
You should have noticed that when using the createObject method, we can specify nonSilverlight effects for Silverlight. This is specified through the altHtml parameter in the param list. In implementation, when we directly use the object tag on the page to render Silverlight You can use the alt attribute to specify nonSilverlight effects, which is the same as inserting HTML code directly into the object tag.
By using the createObject method, we can completely customize the lowSilverlight effect. Here is an example:
http://www.itstrike.cn/Question/Use-JavaScript-to-create-Silverlight-Object-createObject