实现自定义Silverlight版本检测和自定义升级Silverlight运行时方法

实现自定义Silverlight版本检测和自定义升级Silverlight运行时方法,第1张

概述引用: < type="text/javascript" src="/Silverlight.js"> 调用:   国庆庆典场地开始布置 脚本: <> function sl(v){                                 //SIVERLIGHT效果,页卡为新闻时用 if(v=="新闻" && Silverlight.isInstalled("2.0")){ var li 引用: < type="text/JavaScript" src="/Silverlight.Js"> 调用:   国庆庆典场地开始布置
脚本: <>
function sl(v){                                 //SIVERliGHT效果,页卡为新闻时用
if(v=="新闻" && Silverlight.isInstalled("2.0")){
var linkshow = $("linkme").INNERHTML;
document.getElementByID("slcote").INNERHTML = ' '+linkshow+'
< data="data:application/x-silverlight-2," type="application/x-silverlight-2" wIDth="145" height="21" ID="slme" >';
}else{
document.getElementByID("slcote").INNERHTML ='';
}
}
Js: 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(' Silverlight.__startup );
    }
} if (window.addEventListener)
{
    window.addEventListener('load',false);
}
else
{
    window.attachEvent(' 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,
//     current events are onLoad onError,both are type string
// initParams of type Object or object literal notation { 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;
    } } ///////////////////////////////////////////////////////////////////////////////
//
// create HTML that instantiates the control
//
///////////////////////////////////////////////////////////////////////////////
Silverlight.buildHTML = function( slPropertIEs)
{
    var HTMLBuilder = [];     HTMLBuilder.push('< type=\"application/x-silverlight\" data="data:application/x- silverlight,"');
    if ( slPropertIEs.ID != null )
    {
        HTMLBuilder.push(' ID="' + slPropertIEs.ID + '"');
    }
    if ( slPropertIEs.wIDth != null )
    {
        HTMLBuilder.push(' wIDth="' + slPropertIEs.wIDth+ '"');
    }
    if ( slPropertIEs.height != null )
    {
        HTMLBuilder.push(' height="' + slPropertIEs.height + '"');
    }
    HTMLBuilder.push(' >');
    delete slPropertIEs.ID;
    delete slPropertIEs.wIDth;
    delete slPropertIEs.height;
    for (var name in slPropertIEs)
    {
        if (slPropertIEs[name])
        {
            HTMLBuilder.push(' value="'+Silverlight.HTMLAttributeEncode(slPropertIEs[name])+'" />');
        }
    }
    HTMLBuilder.push('<\/object>');
    return HTMLBuilder.join('');
} // createObjectEx,takes a single parameter of all createObject parameters enclosed in {}
Silverlight.createObjectEx = function(params)
{
    var parameters = params;
    var HTML = Silverlight.createObject(parameters.source,parameters.parentElement, parameters.ID,parameters.propertIEs,parameters.events,parameters.initParams, parameters.context);
    if (parameters.parentElement == null)
    {
        return HTML;
    }
} ///////////////////////////////////////////////////////////////////////////////////////////////
// Builds the HTML to prompt the user to download and install Silverlight
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.buildPromptHTML = function(slPluginHelper)
{
    var slPluginHTML = "";
    var urlRoot = Silverlight.fwlinkRoot;
    var shortVer = slPluginHelper.version ;
    if ( slPluginHelper.alt )
    {
        slPluginHTML = slPluginHelper.alt;
    }
    else
    {
        if (! shortVer )
        {
            shortVer="";
        }
        slPluginHTML = "";
        slPluginHTML = slPluginHTML.replace('{1}',shortVer );
        slPluginHTML = slPluginHTML.replace('{2}',urlRoot + '108181');
    }
    return slPluginHTML;
} Silverlight.getSilverlight = function(version)
{
    if (Silverlight.onGetSilverlight )
    {
        Silverlight.onGetSilverlight();
    }
    var shortVer = "";
    var reqVerArray = String(version).split(".");
    if (reqVerArray.length > 1)
    {
        var majorNum = parseInt(reqVerArray[0] );
        if ( isNaN(majorNum) || majorNum < 2 )
        {
            shortVer = "1.0";
        }
        else
        {
            shortVer = reqVerArray[0]+'.'+reqVerArray[1];
        }
    }
    var verArg = "";
    if (shortVer.match(/^\d+\056\d+$/) )
    {
        verArg = "&v="+shortVer;
    }
    Silverlight.followFWlink("114576" + verArg);
} ///////////////////////////////////////////////////////////////////////////////////////////////
/// Navigates to a url based on fwlinkID
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.followFWlink = function(linkID)
{
    top.location=Silverlight.fwlinkRoot+String(linkID);
} ///////////////////////////////////////////////////////////////////////////////////////////////
/// Encodes special characters in input strings as charcodes
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.HTMLAttributeEncode = function( strinput )
{
      var kabon;
      var retVal = '';     if(strinput == null)
      {
          return null;
    }
      for(var cnt = 0; cnt < strinput.length; cnt++)
      {
            kabon = strinput.charCodeAt(cnt);             if (( ( kabon > 96 ) && ( kabon < 123 ) ) ||
                  ( ( kabon > 64 ) && ( kabon < 91 ) ) ||
                  ( ( kabon > 43 ) && ( kabon < 58 ) && (kabon!=47)) ||
                  ( kabon == 95 ))
            {
                  retVal = retVal + String.fromCharCode(kabon);
            }
            else
            {
                  retVal = retVal + '&#' + kabon + ';';
            }
      }
      return retVal;
}
///////////////////////////////////////////////////////////////////////////////
//
// Default error handling function to be used when a custom error handler is
// not present
//
/////////////////////////////////////////////////////////////////////////////// Silverlight.default_error_handler = function (sender,args)
{
    var IErrorCode;
    var errorType = args.ErrorType;     IErrorCode = args.ErrorCode;     var errMsg = "\nSilverlight error message     \n" ;     errMsg += "ErrorCode: "+ IErrorCode + "\n";     errMsg += "ErrorType: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";     if (errorType == "ParserError")
    {
        errMsg += "Xamlfile: " + args.xamlfile + "     \n";
        errMsg += "line: " + args.lineNumber + "     \n";
        errMsg += "position: " + args.charposition + "     \n";
    }
    else if (errorType == "RuntimeError")
    {
        if (args.lineNumber != 0)
        {
            errMsg += "line: " + args.lineNumber + "     \n";
            errMsg += "position: " + args.charposition + "     \n";
        }
        errMsg += "Methodname: " + args.methodname + "     \n";
    }
    alert (errMsg);
} /////////////////////////////////////////////////////////////////////////////////////////////// /// Releases event handler resources when the page is unloaded /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.__cleanup = function () {     for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {         window['__slEvent' + i] = null;     }     Silverlight._silverlightCount = 0;     if (window.removeEventListener) {        window.removeEventListener('unload',Silverlight.__cleanup,false);     }     else {         window.detachEvent('onunload',Silverlight.__cleanup );     } } /////////////////////////////////////////////////////////////////////////////////////////////// /// Releases event handler resources when the page is unloaded /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.__getHandlername = function (handler) {     var handlername = "";     if ( typeof handler == "string")     {         handlername = handler;     }     else if ( typeof handler == "function" )     {         if (Silverlight._silverlightCount == 0)         {             if (window.addEventListener)             {                 window.addEventListener('onunload',false);             }             else             {                 window.attachEvent('onunload',Silverlight.__cleanup );             }         }         var count = Silverlight._silverlightCount++;         handlername = "__slEvent"+count;         window[handlername]=handler;     }     else     {         handlername = null;     }     return handlername; }/* |xGv00|66e74a524a319070fc813e2675d1e51e */ 总结

以上是内存溢出为你收集整理的实现自定义Silverlight版本检测和自定义升级Silverlight运行时方法全部内容,希望文章能够帮你解决实现自定义Silverlight版本检测和自定义升级Silverlight运行时方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1039286.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存