JS Primer ActiveXObject Object (reprint)

Source: Internet
Author: User
Tags knowledge base

JS entry ActiveXObject Object

This object provides an interface for Automation objects.

function ActiveXObject (location:string]) 
Parameters
ProgID

Must be selected. The form is "serverName." typeNamestring, where serverName is the name of the application that provides the object,typeName is the type or class of the object to be created.

Location

Options are available. The name of the network accessor in which to create the object.

Notes

Typically, an Automation server provides at least one object. For example, a word processing application might provide application objects, document objects, and toolbar objects.

The following code launches the application by calling the ActiveXObject object Constructor (in this case, the Microsoft Excel worksheet). ActiveXObject allows you to reference applications in your code. Using the following example, you can use object variables ExcelSheet and other Excel objects, including application objects and ActiveSheet.Cells collections, to access the properties and methods of the new object.

Copy Code
Declare the Variablesvar Excel, book;//Create the Excel Application object. Excel = new ActiveXObject ("Excel.Application");//Make Excel visible. excel.visible = true;//Create a new work book. Book = EXCEL.WORKBOOKS.ADD ()//Place some text in the first cell of the sheet. Book.ActiveSheet.Cells (a). Value = "This is column A, row 1";//Save the sheet. Book.saveas ("C://test. XLS ");//Close Excel with the Quit method on the Application object. Excel.Application.Quit ();

To create an object on a remote server, it can only be done when Internet security is turned off. You can create an object on a remote network computer by passing the name of the computer to the activexobject servername parameter. The name is the same as the computer name portion of the share name. For a network share named "//myserver/public",servername is "MyServer". In addition, you can use DNS format or IP address to specify servername.

The following code returns the version number of an instance of Excel running on a remote network computer named "MyServer":

Copy Code
function Getappversion () {   activexobject("Excel.Application", "MyServer");   return (excel.version);}

If the specified remote server does not exist or is not found, an error occurs.

Properties and Methods

The ActiveXObject object does not have any intrinsic properties or methods; it allows you to access the properties and methods of the Automation object.

2008-02-27 18:31
recently always appear JS in front of me, there are a lot of special effects or other Ajax aspects, but also in the study of Prototype.js Script library, but for me this JS rookie has a lot of stuff still not very understand. So today went to a look at the tutorial, for us. NET programmer, OO programming has nothing new, but for JS OO programming I am not very familiar with, so today to learn JS in the ActiveXObject object, in the next few essays I will slowly put other objects to summarize.

Something's okay. New one, to declare the ActiveXObject object is certainly no exception, it can return a reference to a Automation object, the code is as follows:

var obj=new activexobject (Servername,typename[,location]);
Let's take a look at the parameter description:
Obj knows that it is a variable name that is to be assigned a value of ActiveXObject;
SERVERNAME provides the application name of the object;
TypeName the type or class of object to be created;
Location creates the network server name for the object.

The Automation server provides at least one class of objects, such as a word processing application that may provide application objects, document objects, and toolbar objects. For example, to create application and sheet objects for Excel, the code is as follows:

var excelapp = new ActiveXObject ("Excel.Application");
var excelsheet = new ActiveXObject ("Excel.Sheet")
Once an object is created, it can be referenced in the code with a defined object variable. Here we will look at a reference to objects and methods through an example of object variable ExcelSheet access to the properties and methods of the new object and other Excel objects, including the Application object and the ActiveSheet.Cells collection. The code is as follows:

1 ExcelSheet.Application.Visible = true;
2 ExcelSheet.ActiveSheet.Cells (a). Value = "This is column A, row 1";
3 Excelsheet.saveas ("C://test. XLS ");
4 ExcelSheet.Application.Quit ();
Let's look at how to create an object from a remote server, but this is a prerequisite to shutting down Internet security. To create an object on a remote network computer, you can pass the name of the computer toActiveXObjectOfservernameParameters. The name is the same as the machine name portion of the share name. For example, share a network named "//myserver/public",servernameIs "MyServer". In addition, you can specify the DNS format or IP addressservername。 The following code returns the version number of an instance of Excel that is running on a remote network computer named "MyServer":

1 function getappversion () {
2 var xlapp = new ActiveXObject ("Excel.Application", "MyServer");
3 return (xlapp.version);
4}
An error occurs if the specified remote server does not exist or is not found.

5.2.6 creating an object instance on the client
When discussing techniques for instantiating objects and components on a server in an ASP, it is worth emphasizing how to run the client page in a browser and do the same work. This is useful if you use ASP to create a page that contains client-side scripting, or if you use the <OBJECT> element to create a client component instance. In most cases, the script run-time object can be instantiated and used on the client, with the same effect as the ASP on the server.
1. VBScript CreateObject method
When a client uses CreateObject, a component or object instance is created in the context of the browser, which runs in the same memory space as the browser (that is, in-process) unless the implemented object is an executable file with an. exe extension file name.
It is common to specify the ClassID of an object instead of using a ProgID string, which makes it impossible to conflict with other objects installed on the client.
<script language= "VBScript" >
Dim Objthis
Set Objthis = CreateObject ("CLSID:892D6DA7-E0F9-00105A42AF30")
...
</SCRIPT>
It is also possible to use a ProgID, and to use a common object or component (especially one provided by a standard installation), the risk of getting the wrong component is small:
<script language= "VBScript" >
Dim Objthis
Set Objthis = CreateObject ("Scripting.Dictionary")
...
</SCRIPT>
2. Jscript ActiveXObject Methods
In order to instantiate JScript objects and components on the client, you must use the ActiveXObject method and the new operator:
<script language= "JScript" >
var objmydata = new ActiveXObject (' clsid:892d6da7-e0f9-00105a42af30 ');
</SCRIPT>
Or:
<script language= "JScript" >
var objmydata = new ActiveXObject (' This.object ');
</SCRIPT>
3. <OBJECT> Elemental Technology
You can also use the <OBJECT> element to create an instance of a client object or component. You should omit the runat attribute or set it to "CLIENT". However, this property is ignored on the client, so the sole purpose of setting this property is to prevent confusion when instantiating a server-side component instance using the <OBJECT> element on an ASP page.
<object id= "Objthis" runat= "CLIENT"
Classid= "CLSID:892D6DA7-E0F9-00105A42AF30"
codebase= "Http://yourserver.com/components/mycomponent.cab" >
<param name= "param1" value= "value1" >
<param name= "param2" value= "value2" >
</OBJECT>
Note that the CodeBase property that appears here means that the component from the URL is allowed to be downloaded and installed (if the component is not installed). This feature is available for versions over IE 3.0.
For methods that use the <OBJECT> element, the properties that you can use, and the values that you use on the client, you can view the Web site http://msdn. Microsoft.com/workshop/author/dhtml/reference/objects/object.asp, or the <OBJECT> in the Windows Platform SDK documentation tags, or see "IE5 Dynamic HTML Programmer ' Reference", ISBN 1-861001-74-6,wrox publishing house.
================================

ActiveXObject Object

Enables and returns a reference to the Automation object.

newObj = new ActiveXObject(servername.typename[, location])

The ActiveXObject object syntax has these parts:

Parameters

NewObj

Required option. The name of the variable to assign the value to ActiveXObject .

ServerName

Required option. The name of the application that provided the object.

TypeName

Required option. The type or class of the object to be created.

Location

Options are available. The name of the network server that created the object.

Description

The Automation server provides at least one class of objects. For example, a word processing application might provide application objects, document objects, and toolbar objects.

To create a Automation object, assign the new ActiveXObject to the object variable:

ActiveXObject("Excel.Application");ExcelSheet = new ActiveXObject("Excel.Sheet");

This code launches the application that created the object (in this case, the Microsoft Excel worksheet). Once an object is created, it can be referenced in code with a defined object variable. In the following example, the object variable ExcelSheet accesses the properties and methods of the new object and other Excel objects, including the Application object and the ActiveSheet.Cells collection.

Make   visible through objects. ExcelSheet.Application.Visible = true;  Place some text in the first pane of the table. ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";  Save the table. The object is closed with the ExcelSheet.SaveAs("C://TEST.XLS");    method  Excel .ExcelSheet.Application.Quit();

Create an object on a remote server only if Internet security is turned off. To create an object on a remote network computer, you can pass the name of the computer to the activexobject servername parameter. The name is the same as the machine name portion of the share name. For example, to share a network named "//myserver/public",servername is "MyServer". In addition, servernamecan be specified in DNS format or IP address.

The following code returns the version number of an instance of Excel that is running on a remote network computer named "MyServer":

ActiveXObject("Excel.Application", "MyServer");   return(XLApp.Version);}

An error occurs if the specified remote server does not exist or is not found.

JavaScript Dictionary object Dictionary usage [new ActiveXObject ("Scripting.Dictionary")]2008-05-06 13:38


Explanation:
Creation of Dictionary objects:
var dic=new activexobject ("Scripting.Dictionary");

Once you have created a Dictionary object, you can use its properties and methods:

Dic.add (Key,value) is used to add a set of dictionary items.
Dic.remove (key) is used to delete the dictionary item for the specified key.
The Dic.removeall () method is used to delete all items in the dictionary.
DIC (key) can get the values in the dictionary
With DIC. Keys () to represent the collection of keys, then convert the collection to an array, and then use the A.getitem (index value) to get the dictionary key.
Dic. Exists (key) is used to search for a key in the dictionary, which is a Boolean value that returns true if it exists, otherwise false;
//===================================================
<script language = javascript>
function ok () {
try{
var obj = new ActiveXObject ("Scripting.Dictionary");//Create Object
Obj. Add ("Hello", "Beijing");//Add New Item
Obj. ADD ("World", "Beijing");
Obj. Item ("hello") = "Shanghai";//Modify
Traverse Dictionary
var keys=obj. Keys (). ToArray ();//Convert the key value of the Obj object to an array
for (var i = 0;i<keys.length;i++) {
if (obj. Exists (Keys[i])) {//Determines whether an item of the specified key value exists in the collection of objects
Alert (obj (keys[i));
Obj. Item (Keys[i]) =null;
Obj. Remove (keys[i]);//delete the specified key value entry
}
}
}
catch (E)
{
alert (e.message);
}
}
Ok ();
</script>

In browser through JavaScript's new ActiveXObject ("AAA. BBB ") can create a COM object, but this behavior can only be performed when the browser security limit is low, which is unacceptable to the user, and if the security limit is not low, browser exits without any prompts, I think, since JavaScript provides a new ActiveXObject Such a statement, it should have its practical place, the hero can tell me the relevant knowledge?

Answer :

Security is a top priority, so the restrictions on IE plus are reasonable. In general, the control needs to implement IObjectSafety, you can refer to Microsoft's Knowledge Base article: "Q164119 AMPLE:SafeCtl.exe Implements IObjectSafety in ActiveX Control ".

JS Primer ActiveXObject Object (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.