使用 JavaScript 为你的网页增加 Sliverlight 支持

openkk 13年前
     <p>本文教你如何使用 JavaScript 在网页中嵌入 Sliverlight 组件。</p>    <p>我们需要在 Web 应用中使用到 <a href="/misc/goto?guid=4959500097987237905" rel="nofollow"><b>Silverlight.js</b></a> 这个 JS 文件。</p>    <pre class="brush:html; toolbar: true; auto-links: false;"><script type="text/javascript" src="Silverlight.js"></script></pre>    <p>嵌入该插件:</p>    <pre class="brush:js; toolbar: true; auto-links: false;"><div id="silverlightControlHost">     <script type="text/javascript">          Silverlight.createObject(             "ClientBin/SilverlightApplication1.xap",  // source             silverlightControlHost,  // parent element             "slPlugin",  // id for generated object element             {                 width: "100%", height: "100%", background: "white",                  version:"4.0.60310.0"             },             // See the event handlers in the full example.             { onError: onSLError, onLoad: onSLLoad },             "param1=value1,param2=value2",              "context"    // context helper for onLoad handler.         );     </script>  </div></pre>    <p></p>    <p>参数描述:</p>    <ol>     <li>第一个参数值指定了 Sliverligh 插件的源</li>     <li>第二个参数指定要在那个HTML元素中嵌入这个 Sliverlight 插件</li>     <li>第三个参数是所产生的对象元素的HTML DOM ID</li>     <li>第四个参数为一个数组的属性,如版本、宽度和高度</li>     <li>第五个参数为事件处理器,例如 Onload 和 OnError 事件</li>     <li>第六个参数是一个字符串,包含一些用逗号隔开的参数名和值</li>     <li>最后一个参数是指定生成唯一的 Sliverlight 插件实例</li>    </ol>    <p>如果用户电脑上为安装 Sliverlight ,那么我们需要显示提示信息:</p>    <pre class="brush:js; toolbar: true; auto-links: false;"><div id="silverlightControlHost">     <script type="text/javascript">         var getSilverlightMethodCall =              "javascript:Silverlight.getSilverlight(\"4.0.60310.0\");"         var installImageUrl =             "http://go.microsoft.com/fwlink/?LinkId=161376";         var imageAltText = "Get Microsoft Silverlight";         var altHtml =              "<a href='{1}' style='text-decoration: none;'>" +             "<img src='{2}' alt='{3}' " +             "style='border-style: none'/></a>";         altHtml = altHtml.replace('{1}', getSilverlightMethodCall);         altHtml = altHtml.replace('{2}', installImageUrl);         altHtml = altHtml.replace('{3}', imageAltText);           Silverlight.createObject(             "ClientBin/SilverlightApplication1.xap",              silverlightControlHost, "slPlugin",             {                 width: "100%", height: "100%",                 background: "white", alt: altHtml,                 version: "4.0.60310.0"              },             // See the event handlers in the full example.             { onError: onSLError, onLoad: onSLLoad },             "param1=value1,param2=value2", "row3");     </script> </div></pre>    <p>你还可以使用 Sliverlight.js 提供的更多的 api。</p>    <p>via <a href="/misc/goto?guid=4959500098074318020" rel="nofollow" target="_blank">codeproject</a></p>