Freigeben über


Using Dynamic HTML with Active Channel Sites

This technology is obsolete as of Windows Internet Explorer 7 and should not be used. A variety of Dynamic HTML (DHTML) features can be used to modify the appearance of a Web page, including changing the text or images that are displayed. As an example, the following steps show how a publisher might use the window.external.IShellUIHelper::IsSubscribed method to hide an Add Microsoft Active Channel logo button if the user has already subscribed to the associated channel.

Assuming the Add Active Channel button was placed on a Web page, as described in Developing an Active Channel Site, the page would include the following Add Active Channel button:

<a name="channelA"
href="https://www.microsoft.com/ie/ie40/download/?/ie/ie40/download/redirect.htm">
<img src="IEAddChannel.gif" border=0 width=136 height=20></a>
<script language="JavaScript"> 
    if ( isMsie4orGreater () ) { channelA.href = "urlToCDF"; }
</script> 

Step 1. Add the ID attribute to the anchor element. The value must be unique.

<a name="channelA" id="idA"
href="https://www.microsoft.com/ie/ie40/download/?/ie/ie40/download/redirect.htm">
<img src="IEAddChannel.gif" border=0 width=136 height=20></a>
<script language="JavaScript"> 
    if ( isMsie4orGreater()) { channelA.href ="urlToCDF"; }
</script>

Step 2. Include the following script between the page's beginning and ending head tags. Note that the isMsie4orGreater function should already exist in the head section of this page.

<SCRIPT LANGUAGE="JavaScript">
function HideIfSubscribed(elementID, urlToCDF){
if (window.external.IsSubscribed(urlToCDF)) {
  ss.addRule("#"+ elementID,"visibility: hidden");}}

var ss = null;
ss = document.createStyleSheet()
if(isMsie4orGreater()){ //Test if the browser is IE
// For each element you want to conditionally hide, include the following line
// (uniqueID is the unique value for the ID attribute of the element and
// urlToCDF is the URL to the channel's CDF).
HideIfSubscribed("uniqueID","urlToCDF");
}
</SCRIPT>

When using these scripts, remember that the URLs of the channels must include the same protocol and secondary domain name as the page that contains the scripts. Also, any element in DHTML that has the visibility property can be hidden using the same code.

The following HTML page shows a full example of the scripting shown above.

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
  function isMsie4orGreater() { 
    var ua = window.navigator.userAgent;   
    var msie = ua.indexOf ( "MSIE " );
      if (msie > 0) {
        return (parseInt ( ua.substring ( msie+5, ua.indexOf ( ".", msie ) ) ) >=4)
            && (ua.indexOf("MSIE 4.0b") <0) ;}
      else {return false; } }

    function HideIfSubscribed(elementID, urlToCDF){
        if (window.external.IsSubscribed(urlToCDF))
        {ss.addRule("#"+ elementID,"visibility: hidden");}}

    var ss = null;
    if(isMsie4orGreater()){ //Test if the browser is IE
        ss = document.createStyleSheet()
        HideIfSubscribed("idA","http://www.mycorp.com/channelA.cdf");
    }
</SCRIPT>
</HEAD>

<BODY>
<a name="channelA" id="idA"
href="https://www.microsoft.com/ie/ie40/download/?/ie/ie40/download/redirect.htm">
<img src="IEAddChannel.gif" border=0 width=136 height=20></a>
<script language="JavaScript"> 
    if ( isMsie4orGreater()) { channelA.href ="urlToCDF"; }
</script>

</BODY>
</HTML>

If the Web page contains more than one Add Active Channel or Add to Microsoft Active Desktop logo button, the NAME and ID attributes must be unique.