Partager via


IHTMLStyle2::setExpression method

This element is obsolete and should no longer be used. Sets an expression for the specified object.

Syntax

Integer setExpression(
  [in]           BSTR sPropertyName,
  [in]           BSTR sExpression,
  [in, optional] BSTR sLanguage = JScript
);

Parameters

sPropertyName [in]

BSTR that specifies the name of the property to which expression is added.

sExpression [in]

BSTR that specifies any valid script(JScript, JavaScript, VBSCript) statement without quotations or semicolons. This string can include references to other properties on the current page. Array references are not allowed on object properties included in this script.

sLanguage [in, optional]

BSTR that specifies one of the following values:

JScript

Default. Language is JScript.

VBScript

Language is VBScript.

JavaScript

Language is JavaScript.

Remarks

Use the IHTMLStyle2::setExpression method to add expressions to supported Cascading Style Sheets (CSS) attributes and read/write DHTML Properties. To remove expressions set by IHTMLStyle2::setExpression, use the IHTMLStyle2::removeExpression method.

The following syntax sections show how to set an expression on DHTML Properties and CSS attributes.

  • Use this syntax to set an expression on a read/write property or on an IHTMLDocument2::expando property.

    object.setExpression(sPropertyName, sExpression, sLanguage)
    
  • Use this syntax to set an expression on a CSS attribute.

    object.style.setExpression(sPropertyName, sExpression, sLanguage)
    
  • Use the expression() syntax to set an expression on a CSS attribute in HTML.

    <element style="sAttributeName:expression(sExpression)">
    

The data type of the evaluated expression in the language parameter must match one of the possible values allowed for the expression parameter. If the property or attribute specified by the first parameter requires a string, the data type of the second parameter must be a string. Otherwise, the second parameter is evaluated prior to invoking IHTMLStyle2::setExpression, causing the expression to be set to the result of the evaluation.

Use the IHTMLUniqueName::uniqueID property of an object in an expression to refer back to the object. Using IHTMLUniqueName::uniqueID is an alternative to specifying an IHTMLElement::id for expressions that use an object reference.

The IHTMLRuleStyle::cssText property is a unique property that is not compatible with the dynamic properties implementation. Do not use IHTMLRuleStyle::cssText with any dynamic property methods.

The following examples illustrate common problems encountered with the expression parameter in IHTMLStyle2::setExpression. The expression appears valid, but may not be.

  • The provided expression is invalid because document.style.fontSize is "npx" and will not add to 13

    object.style.setExpression("height","document.style.fontSize + 13"); 
    
  • The provided expression is invalid when document.body.style.fontSize is previously unspecified

    object.style.setExpression("width","document.body.style.fontSize"); 
    

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows 2000 Server

Header

Mshtml.h

IDL

Mshtml.idl

DLL

Mshtml.dll

See also

IHTMLStyle2

Reference

IHTMLStyle2::getExpression

IHTMLStyle2::removeExpression

IHTMLDocument3::recalc

Conceptual

About Dynamic Properties