您的位置:首页 > Web前端 > JavaScript

使用 JavaScript 将 Silverlight 添加到网页

2011-03-19 18:59 477 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<!-- saved from url=(0014)about:internet -->
<head>
<title>EmbeddingWithJS</title>

<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
background: blue;
padding: 0;
margin: 0;
}
</style>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript">
window.onload = function() {
sl1Host.innerHTML = embedSilverlight(null, "sl1", "row1");
}

function embedSilverlight(parentElement, pluginId, userContext) {
var altHtml = pluginId == "sl1" ? null : "<!--not installed-->";
return Silverlight.createObject("ClientBin/EmbeddingWithJS.xap",
parentElement, pluginId,
{
width: "200", height: "50",
background: "white", alt: altHtml,
version:"4.0.50303.0", autoUpgrade:true
},
{ onError: onSLError, onLoad: onSLLoad },
"param1=value1,param2=value2", userContext);
}

function onSLLoad(plugIn, userContext, sender) {
window.status +=
plugIn.id + " loaded into " + userContext + ". ";
}

function onSLError(sender, args) {
// Display error message.
}
</script>
</head>

<body>

<table>
<tr>
<td id="sl1Host"/>
</tr>
<tr>
<td id="sl2Host">
<script type="text/javascript">
embedSilverlight(sl2Host, "sl2", "row2");
</script>
</td>
</tr>
<tr>
<td id="sl3Host">
<script type="text/javascript">
Silverlight.createObject(
"ClientBin/EmbeddingWithJS.xap", sl3Host, "sl3",
{
width: "200", height: "50",
background: "white", alt: "<!--not installed-->",
version: "4.0.50303.0"
},
{ onError: onSLError, onLoad: onSLLoad },
"param1=value1,param2=value2", "row3");
</script>
</td>
</tr>
<tr>
<td id="sl4Host">
<script type="text/javascript">
Silverlight.createObjectEx({
source: "ClientBin/EmbeddingWithJS.xap",
parentElement: sl4Host,
id: "sl4",
properties: {
width: "200",
height: "50",
background: "white",
alt: "<!--not installed-->",
version: "4.0.50303.0" },
events: {
onError: onSLError,
onLoad: onSLLoad },
initParams: "param1=value1,param2=value2",
context: "row4"
});
</script>
</td>
</tr>
</table>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: