marin

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

<object id="Xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="95%">
            <param name="source" value="ClientBin/AOneItem.xap"/>
            <param name="onerror" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="3.0.40624.0" />
            <param name="autoUpgrade" value="true" />
            <%--<param name="Windowless" value="true" />--%>
            <param name="InitParams" value="InitIndex=0,SilverlightID=c1,SilverlightTitle=asdf" />
            <a href="ClientBin/Silverlight.4.0.exe" style="text-decoration: none;">
                <img src="ClientBin/InstallSilverlight.png" alt="获取 Microsoft Silverlight" style="border-style: none"/>
            </a>
        </object

 

经过测试发现上边的方法仅仅支持:客户端没有安装Silverlight插件的请客。当安装了低版本后则任然会跳转到微软的路径..原以为修改silverlight.js可以解决,但是尝试很多后任然不行。于是根据网上提示通过JavaScript调用silverlight.js动态加载silverlight后,终于实现。大致代码如下:

<script type="text/javascript">
        
//用于控制DIV的显示,直接跟ID属性
        function showhidediv(id){
        
var sbtitle=document.getElementById(id);
            
if(sbtitle){
               
if(sbtitle.style.display=='block'){
               sbtitle.style.display
='none';
               }
else{
               sbtitle.style.display
='block';
               }
            }
        }

        
function LoadSilverlight() {
            
//插件版本判断
            var theVersion = "4.0.50401.0"//设定版本检测值 
            var isInstalled = Silverlight.isInstalled(theVersion);
            
if (!isInstalled) {
                
//alert("您的Silverlight插件需要升级,请下载并安装!"); // 安装(提示)体验
                //window.open("http://localhost:10968/Silverlight4.0.exe");
                showhidediv("downSL");

            } 
else {
                
//JavaScript 将 Silverlight 添加到网页
                Silverlight.createObjectEx({
                    source: 
"ClientBin/Main_src.xap",
                    parentElement: silverlightControlHost,
                    id: 
"sl4",
                    properties: {
                        width: 
"100%",
                        height: 
"100%",
                        background: 
"white",
                        alt: 
"<!--Not installed!-->",
                        version: theVersion
                    },
                    events: {
                        onError: onSilverlightError,
                        onLoad: onSLLoad
                    },
                    initParams: 
"bgImage=1.png",//参数
                    context: 
""
                });

            }
         }
         
function onSLLoad(plugIn, userContext, sender) {
             
//alert("加载...");
        }
    
</script>

<body onload="LoadSilverlight()">
    <form id="form1" runat="server" style="height: 100%">
    
    <div id="downSL" style="display:none" >
        <href="ClientBin/Silverlight4.0.exe" style="text-decoration: none;">
            <img src="ClientBin/InstallSilverlight.png" alt="获取 Microsoft Silverlight" style="border-style: none" />
        </a>
    </div>
    <div id="silverlightControlHost">
        <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px;
            border: 0px"
></iframe>
    </div>
    </form>
</body>

  希望对大家有用......

 

posted on 2010-06-10 15:14  marin  阅读(2422)  评论(1)    收藏  举报
五月营销软件