Share via


Specifying and Retrieving Custom Initialization Parameters

The initParams initialization parameter enables you to specify your own parameter values during initialization. These parameter values can be retrieved at run time by accessing the plug-in's InitParams property. The following JavaScript example shows how to specify the initParams parameter value in the user-defined CreateSilverlight method in CreateSilverlight.js.

JavaScript
function createSilverlight()
{  
    Silverlight.createObject(
        "plugin.xaml",                  // Source property value.
        parentElement,                  // DOM reference to hosting DIV tag.
        "myPlugin",                     // Unique plug-in ID value.
        {                               // Plug-in properties.
            width:'600',                // Width of rectangular region of plug-in, in pixels.
            height:'200',               // Height of rectangular region of plug-in, in pixels.
            version:'1.0'               // Plug-in version to use.
        },
        { },                            // No events defined -- use empty list.
        "param1, param2");              // InitParams property value.
}

To access the initParams initialization parameter values at run time, use the InitParams property of the plug-in. The following JavaScript example shows how to retrieve the parameter values by using the InitParams property.

JavaScript
function onLoaded(sender, eventArgs)
{
    // Retrieve a reference to the plug-in.
    var plugin = sender.getHost();
    // Retrieve the InitParams value and split comma-delimited string.
    var params = plugin.initParams.split(",");
    // Display the parameter values.
    var msg = "Params: ";
    for (var i = 0; i < params.length; i++)
    {
        msg += params[i] + " ";
    }
    alert(msg);
}

See Also

Silverlight Object Models and Scripting to the Silverlight Plug-In
Instantiating a Silverlight Plug-In
InitParams
Overviews and How-to Topics