JavaScript
  Home arrow JavaScript arrow Page 14 - JavaScript and Embedded Objects
IBM Rational Software Development Conference
CIO Insight
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JavaScript and Embedded Objects
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 43
    2004-10-26

    Table of Contents:
  • JavaScript and Embedded Objects
  • Java
  • Including Applets
  • Accessing Applets in JavaScript
  • Issues with JavaScript-Driven Applets
  • Plug-ins
  • MIME Types
  • Detecting Specific Plug-Ins
  • Interacting with Plug-Ins
  • Refreshing the Plug-Ins Array
  • Interacting with a Specific Plug-In
  • ActiveX
  • Cross-Browser Inclusion of Embedded Objects
  • Interacting with ActiveX Controls
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Application developers can seamlessly integrate the Advantage Database install with their application install. Learn the best practices used when setting up silent installs with this seminar.

    JavaScript and Embedded Objects - Interacting with ActiveX Controls
    (Page 14 of 15 )

    JavaScript can be used to interact with ActiveX controls in a manner quite similar to plug-ins. A control is accessible under the Document object according to the id of the <object> that included it. If the required control isn’t available, Internet Explorer automatically installs it (subject to user confirmation) and then makes it available for use.


    Note You may have to include the mayscript attribute in the <object> to enable callback functions.

    Any methods exposed by the control are callable from JavaScript in the way applet or plug-in functionality is called. Simply invoke the appropriate function of the <object> in question. To invoke the Play() method of the control in the previous example, you’d write

    document.demoMovie.Play();

    As a quick demonstration, we recast the previous example so it works in both Netscape and Internet Explorer browsers.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Cross-browser Flash Control Example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    <!--
      var dataReady = false;
      var pluginAvailable = false;
      function detectPlugin()
        {
          if (navigator.plugins && 
              ((navigator.plugins["Shockwave Flash"] &&
                navigator.plugins["Shockwave Flash"]["application/x-shockwave-flash"]) 
               || 
               (navigator.plugins["Shockwave Flash 2.0"] &&
                navigator.plugins["Shockwave Flash 2.0"]["application/x-shockwave-flash"])
              )) 
            pluginAvailable = true;
            return(pluginAvailable);
    }

    function changeFrame(i)
    {
        if (!dataReady)
          return;
        // Some versions of the ActiveX control don't support TotalFrames,
        // so the check is omitted here. However, the control handles values
        // out of range gracefully.
        document.demo.GotoFrame(parseInt(i));
    }

    function play()
    {
        if (!dataReady)
          return;
      if (!document.demo.IsPlaying())
        document.demo.Play();
    }

    function stop()
    {
        if (!dataReady)
          return;
        if (document.demo.IsPlaying())
          document.demo.StopPlay();
    }

    function rewind()
    {
        if (!dataReady)
          return;
        if (document.demo.IsPlaying())
          document.demo.StopPlay();
        document.demo.Rewind();
    }
    function zoom(percent)
    {
        if (!dataReady)
          return;
        if (percent > 0)
         
    document.demo.Zoom(parseInt(percent));
    }
    //-->
    </script>
    <head>
    <body onload="dataReady = true;">
    <object id="demo" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    width="318"
    height="300" codebase="http://active.macromedia.com/flash2/
    cabs/swflash.cab#version=5,0,0,0">
    <param name="movie" value="http://demos.javascriptref.com/jscript.swf" />
    <param name="play" value="false" />
    <param name="loop" value="false" />
    <script type="text/javascript">
    <!--
     
    if (detectPlugin())
        {
         
    document.write('<embed name="demo" src="http://demos.javascriptref.com/ jscript.swf" width="318" height="300" play="false" loop="false" pluginspage="http://www.macromedia.com/shockwave/download/ index.cgi?P1_Prod_ Version=ShockwaveFlash5" swliveconnect="true"></embed>');
       
    }
      else
       
    {
          // you can write an image in here in a "real" version
          document.write('Macromedia Flash is required for this demo');
       
    }
    //-->
    </script>
    <noscript>
     
    JavaScript is required to demonstrate this functionality!
    </noscript>
    </object>
    <form name="controlForm" id="controlForm" onsubmit="return false;" action="#" method="get">
    <input type="button" value="Start" onclick="play();" />
    <input type="button" value="Stop" onclick="stop();" />
    <input type="button" value="Rewind" onclick="rewind();" /><br />
    <input type="text" name="whichFrame" id="whichFrame" />
    <input type="button" value="Change Frame"
    onclick="changeFrame(controlForm.whichFrame.value);" /><br />
    <input type="text" name="zoomValue" id="zoomValue" />
    <input type="button" value="Change Zoom"
    onclick="zoom(controlForm.zoomValue.value)" />
    (greater than 100 to zoom out, less
    than 100 to zoom in)<br />
    </form>
    </body>
    </html>

    You might wonder if ActiveX controls can do everything plug-ins can. The answer: yes, and even more. For example, data handled by ActiveX controls can take full advantage of callback functions, so everything that is possible with a plug-in is possible with ActiveX. Further, because data destined for ActiveX is embedded in <object> elements, it can take full advantage of the <object> event handlers defined in (X)HTML. Interestingly, there seems to be more robust support for ActiveX in VBScript than in JavaScript. This is most likely a result of the fact that as a Microsoft technology, VBScript is more closely coupled with Microsoft’s COM. For more information on ActiveX, see http://www.microsoft.com/com/tech/activex.asp.

    McGraw-Hill-OsborneThis chapter is from JavaScript: The Complete Reference, second edition, by Thomas Powell and Fritz Schneider, McGraw-Hill/Osborne, ISBN: 0072253576). Check it out at your favorite bookstore today.

    Buy this book now.

    More JavaScript Articles
    More By McGraw-Hill/Osborne


     

    JAVASCRIPT ARTICLES

    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps
    - Adding Zoom Controls to Yahoo! Maps
    - Working with Yahoo! Maps
    - Building Image Zooming Controls with the DOM...
    - Working with Multiple Graphics for a Zoom Ap...
    - Improving an Image Zooming Application with ...
    - Zooming in on Images with JavaScript
    - JavaScript Date Objects: Universal Coordinat...
    - Javascript Objects: More Date Methods
    - JavaScript Objects: Dates
    - JavaScript Objects: Finishing Strings

    Iron Speed

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway