Home arrow JavaScript arrow Page 14 - JavaScript and Embedded Objects

JavaScript and Embedded Objects

There's more to Web browsers than (X)HTML, CSS, and JavaScript. ActiveX, plug-ins, and other embedded objects help make the Web what it is today. Get the scoop on these and more in this chapter excerpt from JavaScript: The Complete Reference, second edition, by Thomas Powell and Fritz Schneider McGraw-Hill/Osborne, ISBN 0072253576.

Author Info:
By: McGraw-Hill/Osborne
Rating: 4 stars4 stars4 stars4 stars4 stars / 92
October 26, 2004
  1. · JavaScript and Embedded Objects
  2. · Java
  3. · Including Applets
  4. · Accessing Applets in JavaScript
  5. · Issues with JavaScript-Driven Applets
  6. · Plug-ins
  7. · MIME Types
  8. · Detecting Specific Plug-Ins
  9. · Interacting with Plug-Ins
  10. · Refreshing the Plug-Ins Array
  11. · Interacting with a Specific Plug-In
  12. · ActiveX
  13. · Cross-Browser Inclusion of Embedded Objects
  14. · Interacting with ActiveX Controls
  15. · Summary

print this article

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


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">
<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;

function changeFrame(i)
    if (!dataReady)
    // 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.

function play()
    if (!dataReady)
  if (!document.demo.IsPlaying())

function stop()
    if (!dataReady)
    if (document.demo.IsPlaying())

function rewind()
    if (!dataReady)
    if (document.demo.IsPlaying())
function zoom(percent)
    if (!dataReady)
    if (percent > 0)
<body onload="dataReady = true;">
<object id="demo" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
height="300" codebase="http://active.macromedia.com/flash2/
<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>');
      // you can write an image in here in a "real" version
      document.write('Macromedia Flash is required for this demo');
JavaScript is required to demonstrate this functionality!
<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 />

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.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials