locked
客户端runtime升级问题!! RRS feed

  • 问题

  • 如果库户端浏览器装有runtime3.0,这时候我的服务器端已经升级为4.0了,这时候客户端浏览器打开网站的时候就会自动提示是否升级,这个升级指向的是ms的服务器,能不能指向我指定的服务器。

    说明:客户端没有任何版本的runtime的话,通过修改宿主页面的连接就可以了,这问题已经解决。
    现在的问题就是,客户端有低版本的runtime怎么从本地服务器升级。

    2010年1月6日 8:18

答案

  • 参考一下,判断Silverlight版本,设置升级:

    if (!window.Silverlight)
    {
        window.Silverlight = { };
    }
    
    // Silverlight control instance counter for memory mgt
    Silverlight._silverlightCount = 0;
    Silverlight.fwlinkRoot='http://go2.microsoft.com/fwlink/?LinkID='; 
    Silverlight.onGetSilverlight = null;
    Silverlight.onSilverlightInstalled = function () {window.location.reload(false);};
    
    //////////////////////////////////////////////////////////////////
    // isInstalled, checks to see if the correct version is installed
    //////////////////////////////////////////////////////////////////
    Silverlight.isInstalled = function(version)
    {
        var isVersionSupported=false;
        var container = null;
        
        try 
        {
            var control = null;
            
            try
            {
                control = new ActiveXObject('AgControl.AgControl');
                if ( version == null )
                {
                    isVersionSupported = true;
                }
                else if ( control.IsVersionSupported(version) )
                {
                    isVersionSupported = true;
                }
                control = null;
            }
            catch (e)
            {
                var plugin = navigator.plugins["Silverlight Plug-In"] ;
                if ( plugin )
                {
                    if ( version === null )
                    {
                        isVersionSupported = true;
                    }
                    else
                    {
                        var actualVer = plugin.description;
                        if ( actualVer === "1.0.30226.2")
                            actualVer = "2.0.30226.2";
                        var actualVerArray =actualVer.split(".");
                        while ( actualVerArray.length > 3)
                        {
                            actualVerArray.pop();
                        }
                        while ( actualVerArray.length < 4)
                        {
                            actualVerArray.push(0);
                        }
                        var reqVerArray = version.split(".");
                        while ( reqVerArray.length > 4)
                        {
                            reqVerArray.pop();
                        }
                        
                        var requiredVersionPart ;
                        var actualVersionPart
                        var index = 0;
                        
                        
                        do
                        {
                            requiredVersionPart = parseInt(reqVerArray[index]);
                            actualVersionPart = parseInt(actualVerArray[index]);
                            index++;
                        }
                        while (index < reqVerArray.length && requiredVersionPart ===
    
    actualVersionPart);
                        
                        if ( requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart) )
                        {
                            isVersionSupported = true;
                        }
                    }
                }
            }
        }
        catch (e) 
        {
            isVersionSupported = false;
        }
        if (container) 
        {
            document.body.removeChild(container);
        }
        
        return isVersionSupported;
    }
    Silverlight.WaitForInstallCompletion = function()
    {
        if ( ! Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled )
        {
            try
            {
                navigator.plugins.refresh();
            }
            catch(e)
            {
            }
            if ( Silverlight.isInstalled(null) )
            {
                Silverlight.onSilverlightInstalled();
            }
            else
            {
                  setTimeout(Silverlight.WaitForInstallCompletion, 3000);
            }    
        }
    }
    Silverlight.__startup = function()
    {
        Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);//(!window.ActiveXObject
    
    || Silverlight.isInstalled(null));
        if ( !Silverlight.isBrowserRestartRequired)
        {
            Silverlight.WaitForInstallCompletion();
        }
        if (window.removeEventListener) { 
           window.removeEventListener('load', Silverlight.__startup , false);
        }
        else { 
            window.detachEvent('onload', Silverlight.__startup );
        }
    }
    
    if (window.addEventListener) 
    {
        window.addEventListener('load', Silverlight.__startup , false);
    }
    else 
    {
        window.attachEvent('onload', Silverlight.__startup );
    }
    
    ///////////////////////////////////////////////////////////////////////////////
    // createObject(); Params:
    // parentElement of type Element, the parent element of the Silverlight Control
    // source of type String
    // id of type string
    // properties of type String, object literal notation { name:value, name:value, name:value},
    //     current properties are: width, height, background, framerate, isWindowless,
    
    enableHtmlAccess, inplaceInstallPrompt: all are of type string
    // events of type String, object literal notation { name:value, name:value, name:value},
    //     current events are onLoad onError, both are type string
    // initParams of type Object or object literal notation { name:value, name:value, name:value}
    // userContext of type Object
    /////////////////////////////////////////////////////////////////////////////////
    
    Silverlight.createObject = function(source, parentElement, id, properties, events, initParams,
    
    userContext)
    {
        var slPluginHelper = new Object();
        var slProperties = properties;
        var slEvents = events;
        
        slPluginHelper.version = slProperties.version;
        slProperties.source = source;    
        slPluginHelper.alt = slProperties.alt;
        
        //rename properties to their tag property names
        if ( initParams )
            slProperties.initParams = initParams;
        if ( slProperties.isWindowless && !slProperties.windowless)
            slProperties.windowless = slProperties.isWindowless;
        if ( slProperties.framerate && !slProperties.maxFramerate)
            slProperties.maxFramerate = slProperties.framerate;
        if ( id && !slProperties.id)
            slProperties.id = id;
        
        // remove elements which are not to be added to the instantiation tag
        delete slProperties.ignoreBrowserVer;
        delete slProperties.inplaceInstallPrompt;
        delete slProperties.version;
        delete slProperties.isWindowless;
        delete slProperties.framerate;
        delete slProperties.data;
        delete slProperties.src;
        delete slProperties.alt;
    
    
        // detect that the correct version of Silverlight is installed, else display install
    
        if (Silverlight.isInstalled(slPluginHelper.version))
        {
            //move unknown events to the slProperties array
            for (var name in slEvents)
            {
                if ( slEvents[name])
                {
                    if ( name == "onLoad" && typeof slEvents[name] == "function" && slEvents
    
    [name].length != 1 )
                    {
                        var onLoadHandler = slEvents[name];
                        slEvents[name]=function (sender){ return onLoadHandler
    
    (document.getElementById(id), userContext, sender)};
                    }
                    var handlerName = Silverlight.__getHandlerName(slEvents[name]);
                    if ( handlerName != null )
                    {
                        slProperties[name] = handlerName;
                        slEvents[name] = null;
                    }
                    else
                    {
                        throw "typeof events."+name+" must be 'function' or 'string'";
                    }
                }
            }
            slPluginHTML = Silverlight.buildHTML(slProperties);
        }
        //The control could not be instantiated. Show the installation prompt
        else 
        {
            slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
        }
    
        // insert or return the HTML
        if(parentElement)
        {
            parentElement.innerHTML = slPluginHTML;
        }
        else
        {
            return slPluginHTML;
        }
    
    }
    
    //希望对你有用

    My blog: http://blog.csdn.net/dotfun http://dotfun.cnblogs.com

    My contact: QQ:372900288 E-mail:372900288@qq.com msn:sellnet007@hotmail.com


    《银光志--Silverlight 3.0开发详解与最佳实践》
    2010年1月11日 13:57
  • 检测客户端是否安装 Silverlight 插件
     <script type="text/javascript">  
    function CheckSilverlightInstalled()  
    {  
    var isSilverlightInstalled = false;   
    try{  
    try{  
    var slControl = new ActiveXObject('AgControl.AgControl'); //检查IE  
    isSilverlightInstalled = true;   
    }  
    catch(e){   
    if(navigator.plugins["Silverlight Plug-In"]) //检查非IE  
    {  
    isSilverlightInstalled = true;   
    }  
    }  
    }  
    catch(e){}  
    return isSilverlightInstalled;   
    }  
    alert("是否安装了 Silverlight 插件?" + CheckSilverlightInstalled())  
    </script> 
    <script type="text/javascript">
    function CheckSilverlightInstalled()
    {
    var isSilverlightInstalled = false;
    try{
    try{
    var slControl = new ActiveXObject('AgControl.AgControl'); //检查IE
    isSilverlightInstalled = true;
    }
    catch(e){
    if(navigator.plugins["Silverlight Plug-In"]) //检查非IE
    {
    isSilverlightInstalled = true;
    }
    }
    }
    catch(e){}
    return isSilverlightInstalled;
    }
    alert("是否安装了 Silverlight 插件?" + CheckSilverlightInstalled())
    </script>

    JS判断IE是否安装或支持Silverlight!(只能检测IE)

    JS判断IE是否安装或支持Silverlight!
    JS中可以使用try,catch语名判断客户端是否安装了Silverlight插件,使用插件的IsVersionSupported方法判断目前客户端是否支持指定版本的Silverlight程序!
    view plaincopy to clipboardprint?
      

    由于ASP.NET 中的 Silverlight控件使用了这种检测,所以如果您使用了此控件就可以直接使用方法“Silverlight.isInstalled(version)”调用了!

    http://blog.csdn.net/dotfun/archive/2010/01/11/5178121.aspx


    My blog: http://blog.csdn.net/dotfun http://dotfun.cnblogs.com

    My contact: QQ:372900288 E-mail:372900288@qq.com msn:sellnet007@hotmail.com


    《银光志--Silverlight 3.0开发详解与最佳实践》
    2010年1月11日 14:06

全部回复

  • 我想到的一种办法是你用一个低版本的SL程序运行一下,然后在APP类里判断一下RT的版本,如果RT比较高就提示升级然后HTMLPAGE.NAV...(slverlight4.exe),可以加我QQ:372900288一起讨论一下!

    My blog: http://blog.csdn.net/dotfun http://dotfun.cnblogs.com

    My contact: QQ:372900288 E-mail:372900288@qq.com msn:sellnet007@hotmail.com

    2010年1月7日 9:30
  • 版主帮忙啊!!!!!!!!!!!!!!

    2010年1月11日 3:05
  • 参考一下,判断Silverlight版本,设置升级:

    if (!window.Silverlight)
    {
        window.Silverlight = { };
    }
    
    // Silverlight control instance counter for memory mgt
    Silverlight._silverlightCount = 0;
    Silverlight.fwlinkRoot='http://go2.microsoft.com/fwlink/?LinkID='; 
    Silverlight.onGetSilverlight = null;
    Silverlight.onSilverlightInstalled = function () {window.location.reload(false);};
    
    //////////////////////////////////////////////////////////////////
    // isInstalled, checks to see if the correct version is installed
    //////////////////////////////////////////////////////////////////
    Silverlight.isInstalled = function(version)
    {
        var isVersionSupported=false;
        var container = null;
        
        try 
        {
            var control = null;
            
            try
            {
                control = new ActiveXObject('AgControl.AgControl');
                if ( version == null )
                {
                    isVersionSupported = true;
                }
                else if ( control.IsVersionSupported(version) )
                {
                    isVersionSupported = true;
                }
                control = null;
            }
            catch (e)
            {
                var plugin = navigator.plugins["Silverlight Plug-In"] ;
                if ( plugin )
                {
                    if ( version === null )
                    {
                        isVersionSupported = true;
                    }
                    else
                    {
                        var actualVer = plugin.description;
                        if ( actualVer === "1.0.30226.2")
                            actualVer = "2.0.30226.2";
                        var actualVerArray =actualVer.split(".");
                        while ( actualVerArray.length > 3)
                        {
                            actualVerArray.pop();
                        }
                        while ( actualVerArray.length < 4)
                        {
                            actualVerArray.push(0);
                        }
                        var reqVerArray = version.split(".");
                        while ( reqVerArray.length > 4)
                        {
                            reqVerArray.pop();
                        }
                        
                        var requiredVersionPart ;
                        var actualVersionPart
                        var index = 0;
                        
                        
                        do
                        {
                            requiredVersionPart = parseInt(reqVerArray[index]);
                            actualVersionPart = parseInt(actualVerArray[index]);
                            index++;
                        }
                        while (index < reqVerArray.length && requiredVersionPart ===
    
    actualVersionPart);
                        
                        if ( requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart) )
                        {
                            isVersionSupported = true;
                        }
                    }
                }
            }
        }
        catch (e) 
        {
            isVersionSupported = false;
        }
        if (container) 
        {
            document.body.removeChild(container);
        }
        
        return isVersionSupported;
    }
    Silverlight.WaitForInstallCompletion = function()
    {
        if ( ! Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled )
        {
            try
            {
                navigator.plugins.refresh();
            }
            catch(e)
            {
            }
            if ( Silverlight.isInstalled(null) )
            {
                Silverlight.onSilverlightInstalled();
            }
            else
            {
                  setTimeout(Silverlight.WaitForInstallCompletion, 3000);
            }    
        }
    }
    Silverlight.__startup = function()
    {
        Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);//(!window.ActiveXObject
    
    || Silverlight.isInstalled(null));
        if ( !Silverlight.isBrowserRestartRequired)
        {
            Silverlight.WaitForInstallCompletion();
        }
        if (window.removeEventListener) { 
           window.removeEventListener('load', Silverlight.__startup , false);
        }
        else { 
            window.detachEvent('onload', Silverlight.__startup );
        }
    }
    
    if (window.addEventListener) 
    {
        window.addEventListener('load', Silverlight.__startup , false);
    }
    else 
    {
        window.attachEvent('onload', Silverlight.__startup );
    }
    
    ///////////////////////////////////////////////////////////////////////////////
    // createObject(); Params:
    // parentElement of type Element, the parent element of the Silverlight Control
    // source of type String
    // id of type string
    // properties of type String, object literal notation { name:value, name:value, name:value},
    //     current properties are: width, height, background, framerate, isWindowless,
    
    enableHtmlAccess, inplaceInstallPrompt: all are of type string
    // events of type String, object literal notation { name:value, name:value, name:value},
    //     current events are onLoad onError, both are type string
    // initParams of type Object or object literal notation { name:value, name:value, name:value}
    // userContext of type Object
    /////////////////////////////////////////////////////////////////////////////////
    
    Silverlight.createObject = function(source, parentElement, id, properties, events, initParams,
    
    userContext)
    {
        var slPluginHelper = new Object();
        var slProperties = properties;
        var slEvents = events;
        
        slPluginHelper.version = slProperties.version;
        slProperties.source = source;    
        slPluginHelper.alt = slProperties.alt;
        
        //rename properties to their tag property names
        if ( initParams )
            slProperties.initParams = initParams;
        if ( slProperties.isWindowless && !slProperties.windowless)
            slProperties.windowless = slProperties.isWindowless;
        if ( slProperties.framerate && !slProperties.maxFramerate)
            slProperties.maxFramerate = slProperties.framerate;
        if ( id && !slProperties.id)
            slProperties.id = id;
        
        // remove elements which are not to be added to the instantiation tag
        delete slProperties.ignoreBrowserVer;
        delete slProperties.inplaceInstallPrompt;
        delete slProperties.version;
        delete slProperties.isWindowless;
        delete slProperties.framerate;
        delete slProperties.data;
        delete slProperties.src;
        delete slProperties.alt;
    
    
        // detect that the correct version of Silverlight is installed, else display install
    
        if (Silverlight.isInstalled(slPluginHelper.version))
        {
            //move unknown events to the slProperties array
            for (var name in slEvents)
            {
                if ( slEvents[name])
                {
                    if ( name == "onLoad" && typeof slEvents[name] == "function" && slEvents
    
    [name].length != 1 )
                    {
                        var onLoadHandler = slEvents[name];
                        slEvents[name]=function (sender){ return onLoadHandler
    
    (document.getElementById(id), userContext, sender)};
                    }
                    var handlerName = Silverlight.__getHandlerName(slEvents[name]);
                    if ( handlerName != null )
                    {
                        slProperties[name] = handlerName;
                        slEvents[name] = null;
                    }
                    else
                    {
                        throw "typeof events."+name+" must be 'function' or 'string'";
                    }
                }
            }
            slPluginHTML = Silverlight.buildHTML(slProperties);
        }
        //The control could not be instantiated. Show the installation prompt
        else 
        {
            slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
        }
    
        // insert or return the HTML
        if(parentElement)
        {
            parentElement.innerHTML = slPluginHTML;
        }
        else
        {
            return slPluginHTML;
        }
    
    }
    
    //希望对你有用

    My blog: http://blog.csdn.net/dotfun http://dotfun.cnblogs.com

    My contact: QQ:372900288 E-mail:372900288@qq.com msn:sellnet007@hotmail.com


    《银光志--Silverlight 3.0开发详解与最佳实践》
    2010年1月11日 13:57
  • 检测客户端是否安装 Silverlight 插件
     <script type="text/javascript">  
    function CheckSilverlightInstalled()  
    {  
    var isSilverlightInstalled = false;   
    try{  
    try{  
    var slControl = new ActiveXObject('AgControl.AgControl'); //检查IE  
    isSilverlightInstalled = true;   
    }  
    catch(e){   
    if(navigator.plugins["Silverlight Plug-In"]) //检查非IE  
    {  
    isSilverlightInstalled = true;   
    }  
    }  
    }  
    catch(e){}  
    return isSilverlightInstalled;   
    }  
    alert("是否安装了 Silverlight 插件?" + CheckSilverlightInstalled())  
    </script> 
    <script type="text/javascript">
    function CheckSilverlightInstalled()
    {
    var isSilverlightInstalled = false;
    try{
    try{
    var slControl = new ActiveXObject('AgControl.AgControl'); //检查IE
    isSilverlightInstalled = true;
    }
    catch(e){
    if(navigator.plugins["Silverlight Plug-In"]) //检查非IE
    {
    isSilverlightInstalled = true;
    }
    }
    }
    catch(e){}
    return isSilverlightInstalled;
    }
    alert("是否安装了 Silverlight 插件?" + CheckSilverlightInstalled())
    </script>

    JS判断IE是否安装或支持Silverlight!(只能检测IE)

    JS判断IE是否安装或支持Silverlight!
    JS中可以使用try,catch语名判断客户端是否安装了Silverlight插件,使用插件的IsVersionSupported方法判断目前客户端是否支持指定版本的Silverlight程序!
    view plaincopy to clipboardprint?
      

    由于ASP.NET 中的 Silverlight控件使用了这种检测,所以如果您使用了此控件就可以直接使用方法“Silverlight.isInstalled(version)”调用了!

    http://blog.csdn.net/dotfun/archive/2010/01/11/5178121.aspx


    My blog: http://blog.csdn.net/dotfun http://dotfun.cnblogs.com

    My contact: QQ:372900288 E-mail:372900288@qq.com msn:sellnet007@hotmail.com


    《银光志--Silverlight 3.0开发详解与最佳实践》
    2010年1月11日 14:06