MeadCo ScriptX 5.0
December, 1999
Download this document set (37Kb zip)
MeadCo ScriptX is a non-visual ActiveX control, originally designed to extend the scripting capabilities of the standard Microsoft Scripting Languages JScript» and VBScript» and add more resemblance between the two. Currently the functionality provided by ScriptX can be conditionally grouped under the following headings:
The basic functionality of ScriptX is licensed free of charge. With the ScriptX 5.0 release we added some advanced printing features which are only accessible in the presence of a paid-for MeadCo Security Manager publishing license
ScriptX comes in two signed CABs: ScriptX.cab or smsx.cab, both of which are part of a download package obtainable from the ScriptX site». Authors should select one of them to reference from an HTML page. ScriptX.cab contains only the ScriptX component (MCScriptX.dll) to be used whenever the basic functionality is enough:
<object id=factory style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext codebase="ScriptX.cab#Version=5,0,5,35"> </object>
The viewastext parameter prevents an authoring tool like FrontPage or Visual Interdev from instantiating the object at design time.
smsx.cab contains both the MeadCo ScriptX and Security Manager binaries required to publish content that uses advanced printing:
<!-- MeadCo Security Manager -->
<object viewastext style="display:none"
classid="clsid:5445be81-b796-11d2-b931-002018654e2e"
codebase="smsx.cab#Version=5,0,5,35">
<param name="GUID" value="{9bc82a21-b8c9-11d3-b934-002018654e2e}">
<param name="Path" value="sxlic.mlf">
<param name="Revision" value="0">
</object>
<!-- MeadCo ScriptX -->
<object id=factory viewastext style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="smsx.cab#Version=5,0,5,35">
</object>
Note: the {9bc82a21-b8c9-11d3-b934-002018654e2e} value of the GUID parameter used above identifies the MeadCo evaluation license that authors may use to experiment with Advanced printing capabilities. The license validates local filesystem (file://) and local website (http://localhost/) content for evaluation purposes only on a single development computer. Registered customers are issued with an unique license identifier and a signed sxlic.mlf file. See the licensing» page for more details.
ScriptX became well know for its HTML printing capabilties following our MSDN publication». Version 1.0 provided scripted control of the printing of HTML frame or window content (with or without a prompt), and the specification by script of printing parameters such as headers, footers, page orientation and margins.
ScriptX 5.0 extends basic printing functionality with some powerful new features:
Features marked with * require licensing» from MeadCo.
ScriptX 5.0 is backwards compatible. A number of issues have been resolved since version 1.0, and we strongly recommend that you upgrade your <OBJECT> tags to version 5.0.
The following code snippet illustrates how to customize various printing settings:
<script>
function SetPrintSettings() {
// -- extended features
factory.printing.SetMarginMeasure(2) // measure margins in inches
factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4"
factory.printing.paperSource = "Manual feed"
factory.printing.printer = "HP DeskJet 870C"
// -- basic features
factory.printing.header = "This is MeadCo"
factory.printing.footer = "Advanced Printing by ScriptX 5.0"
factory.printing.portrait = false
factory.printing.leftMargin = 1.0
factory.printing.topMargin = 1.0
factory.printing.rightMargin = 1.0
factory.printing.bottomMargin = 1.0
}
</script>
A subtle JScript issue may occur when setting a printer name that contains back slashes. Don't forget to double the slashes:
factory.printing.printer = "\\\\FS-LYS-01\\HP5n-759" // print to \\FS-LYS-01\HP5n-759
To print specific information as part of the header or footer, include the following characters as part of the text:
| Shorthand | Meaning |
| &w | Window title |
| &u | Page address (URL) |
| &d | Date in short format (as specified by Regional Settings in Control Panel) |
| &D | Date in long format (as specified by Regional Settings in Control Panel) |
| &t | Time in the format specified by Regional Settings in Control Panel |
| &T | Time in 24-hour format |
| &p | Current page number |
| &P | Total number of pages |
| && | A single ampersand (&) |
| &b | The text immediately following these characters as centered. |
| &b&b | The text immediately following the first "&b" as centered, and the text following the second "&b" as right-justified. |
Here are some illustrative examples of ScriptX basic and advanced printing.
See also: printing, header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, Print, DoPrint, PrintHTML, SetPageRange, SetMarginMeasure.
As its name may indicate, DEB enables the binding/unbinding of a script handler to any ActiveX object event on the fly. It works well for all Active Scripting hosts: WSH, HTML or custom.
Another useful DEB feature is the ability to 'sleep' the script execution (with an optional timeout) without any CPU 'eating' until an event occurs. 'Sleep' is conceptually close to VB's DoEvents» statement in that it serves the application message loop.
The best way to illustrate DEB is by example. Here is a Windows Scripting Host (WSH») example in both JScript and VBScript that creates and navigates an instance of the InternetExplorer» object and hooks up to its events.
See also: eventSink, NewEventSink, Wait, CancelWait.
Here is an example of a native look & feel HTML dialog.
See also: ShowHtmlDialog.
These extensions were designed to provide JScript with more resemblance to VBScript.
Jscript has limited read-only support for VB Arrays» (known also as SafeArrays) with a VBArray» object. ScriptX allows the creation of -- and direct access to -- a SafeArray with JScript. It's now possible to convert a JScript Array» to a SafeArray. Note that only single dimension SafeArrays are supported. Here is an example illustrating SafeArrays with JScript.
See also: Vec, VecFill, VecCopy, VecFromArray, VecGetSize, VecResize, VecPut, VecGet, VarType
Invoke 'ByRef' was developed to allow JScript to call ActiveX controls that take byref arguments. It also allows OLE errors that the calling method may return to be handled, and any corresponding script exceptions to be avoided. Here is an example illustrating how to use InvokeByRefResult with JScript.
See also: InvokeByRef, InvokeByRefResult.
Formatting functions match those of VBScript. They require the newer OLE Automation binaries to be available (they're part of Windows 98, come with Internet Explorer 5, or can be downloaded as part of free Visual Basic 6.0 Run-Time», see MSKB Q192461»). Here is an example of JScript formatting.
See also: Format, FormatCurrency», FormatDateTime», FormatNumber», FormatPercent».
It's possible to discover -- on the fly -- which methods and properties an object supports. Microsoft's OleViewer» is required and is available for free download». Here is an example of how to use the object viewer which shows the object model of an HTML window» and the ScriptX factory object itself.
See also: BrowseObject.
See also: Shutdown, IsClosed, GetComponentVersion, MessageBeep, MessageBox, WinHelp, HtmlHelp.
When ScriptX is hosted as an <OBJECT> on an HTML page it provides the following Internet Explorer specific functionality:
We provide free peer-to-peer technical support at the public ScriptX Newsgroup: news://news.the-internet-eye.com/meadco.scriptx. Priority technical support is available to our licensee customers at scriptx@meadroid.com.
factory, js, printing, eventSink
script, baseURL, relativeURL, printing, js, sourceText, header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, handler, src, ctx
NewEventSink, IsClosed, Shutdown, ShowHtmlDialog, MessageBeep, MessageBox, DoPrint, Wait, CancelWait, IsIEBuildGE, OnDocumentComplete, GetComponentVersion, Print, SetPageRange, PrintHTML, SetMarginMeasure, GetMarginMeasure, Vec, VecFill, VecCopy, VecFromArray, VecGetSize, VecResize, VecPut, VecGet, Format, FormatCurrency, FormatDateTime, FormatNumber, FormatPercent, InvokeByRef, InvokeByRefResult, Unadvise, IsSpooling, PrintXML, EnumPrinters, DefaultPrinter, EnumJobs, OwnQueue
Represents the ScriptX object itself as it is named on an HTML page. It's possible to create a ScriptX instance dynamically with the JScript new ActiveXObject» or the VBScript CreateObject». In such cases the Shutdown method should be called when ScriptX is no longer being used.
HTML page:
<object id=factory style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext codebase="ScriptX.cab#Version=5,0,5,35"> </object>WSH» script (JScript):
var factory = new ActiveXObject("ScriptX.Factory") factory.printing.PrintHTML("http://msdn.microsoft.com/workshop/author/script/dhtmlprint.asp") factory.Shutdown()ASP page (VBScript):
<% set factory = CreateObject("ScriptX.Factory") factory.printing.PrintHTML "http://localhost/orders/order.asp?number=" & Request.Form("number") factory.Shutdown set factory = nothing %>
NewEventSink, IsClosed, Shutdown, ShowHtmlDialog, MessageBeep, MessageBox, BrowseObject, DoPrint, PageSetup, WinHelp, HtmlHelp, Timeout, KillTimeout, Wait, CancelWait, IsIEBuildGE, OnDocumentComplete, GetComponentVersion
Represents the printing facilities of ScriptX. See HTML Printing for more information and examples.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize
Print, SetPageRange, PrintHTML, SetMarginMeasure, IsSpooling, PrintXML, EnumPrinters
Represents ScriptX helper facilities for JScript. See JScript: SafeArrays, Invoke 'ByRef', Formatting for more information and examples.
Vec, VecFill, VecCopy, VecFromArray, VecGetSize, VecResize, VecPut, VecGet, Format, FormatCurrency, FormatDateTime, FormatNumber, FormatPercent, InvokeByRef, InvokeByRefResult, VarType
An object used to connect script handlers to, or disconnect them from, events of an ActiveX control. The object is created dynamically with the NewEventSink method. See Dynamic Event Binding (DEB) for more information.
This property is for use with dynamic event binding, when a ScriptX object is created dynamically with VBscript. In this case the script namespace object should be assigned to this property, because ScriptX looks for an event handler by name. See the example below.
factory.script = object
This read/write property takes an object that has all the event handlers defined within.
' Handle events from browser
Set Browser = CreateObject("InternetExplorer.Application")
Browser.Visible = true
Set Factory = CreateObject("ScriptX.Factory")
Factory.script = me
Set Sink = Factory.NewEventSink(Browser)
Sink("BeforeNavigate2")="BeforeNavigate2"
Sink("DocumentComplete")="DocumentComplete"
Sink("OnQuit")="OnQuit"
Sub BeforeNavigate2(ByVal pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel)
' handling code
End Sub
Sub DocumentComplete(ByVal pDisp, URL)
' handling code
End Sub
Sub OnQuit
' handling code
End Sub
This property is for use in an HTML script. It returns a full URL based upon the URL of the hosting document.
fullUrl = factory.baseURL[(url)]
This is a read-only property which returns either the full URL of the hosting document or the base url of the document's URL.
<script>
function window.onload() {
childWindow.navigate(factory.baseURL("loaded.htm"))
}
</script>
This property is for use in an HTML script. It returns the URL relative to the hosting document's URL.
relUrl = factory.relativeURL[(url)]
This is a read-only property.
This property is for use in an HTML script. It retrieves the raw HTML source of the hosting document.
htmlText = factory.sourceText
This is a read-only property.
Specifies the string to be used as the header for HTML print-outs. See HTML Printing for more information and examples.
printing.header = sHeader
This is a read/write property.
footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the string to be used as the footer for HTML print-outs. See HTML Printing for more information and examples.
printing.footer = sFooter
This is a read/write property.
header, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the page orientation for HTML print-outs. See HTML Printing for more information and examples.
printing.portrait = bool
This is a read/write property. Use true to specify portrait and false for landscape.
header, footer, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the left margin for HTML print-outs. ScriptX uses the default units of measure of the user's system (could be either inches or millimeters). In a broad network environment default units are certain to vary, so an author should specify the SetMarginMeasure property. See HTML Printing for more information and examples.
printing.leftMargin = numMargin
This is a read/write property.
header, footer, portrait, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the right margin for HTML print-outs. ScriptX uses the default units of measure of the user's system (could be either inches or millimeters). In a broad network environment default units are certain to vary, so an author should specify the SetMarginMeasure property. See HTML Printing for more information and examples.
printing.rightMargin = numMargin
This is a read/write property.
header, footer, portrait, leftMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the top margin for HTML print-outs. ScriptX uses the default units of measure of the user's system (could be either inches or millimeters). In a broad network environment default units are certain to vary, so an author should specify the SetMarginMeasure property. See HTML Printing for more information and examples.
printing.topMargin = numMargin
This is a read/write property.
header, footer, portrait, leftMargin, rightMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the bottom margin for HTML print-outs. ScriptX uses the default units of measure of the user's system (could be either inches or millimeters). In a broad network environment default units are certain to vary, so an author should specify the SetMarginMeasure property. See HTML Printing for more information and examples.
printing.bottomMargin = numMargin
This a read/write property.
header, footer, portrait, leftMargin, rightMargin, topMargin, paperSize, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the paper size for HTML print-outs. Only the paper size strings as they appear on Internet Explorer's "Page Setup" dialog for the selected printer can be specified. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.paperSize = sPaperSize
This is a write-only property.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSource, copies, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the paper source for HTML print-outs. Only the paper source strings as they appear on Internet Explorer's "Page Setup" dialog for the selected printer can be specified. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.paperSource = sPaperSize
This is a write-only property.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, copies, collate, printer, printBackground, fontSize, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the number of copies for HTML print-outs. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.copies = numCopies
This a write-only property.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, collate, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies whether or not to collate the pages of HTML print-outs when more than one copy is printed. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.collate = bool
This is a write-only property. Use true to collate.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, printer, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the printer to print to. Only the printer names as they appear on Internet Explorer's "Print" dialog can be specified. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.printer = sPrinterName
This a write-only property. With JScript, take care to double a backslash if one appears in the printer name.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, fontSize, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies the font size for HTML print-outs. 0 corresponds to smallest, 4 to largest. This setting doesn't affect the font size set with CSS. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.fontSize = numSize
This is a write-only property.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, printBackground, Print, SetPageRange, PrintHTML, SetMarginMeasure
Specifies whether or not to print a page's background colors and images. To use this property, a publishing license» is required. See HTML Printing for more information and examples.
printing.printBackground = true|false
This is a write-only property.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, Print, SetPageRange, PrintHTML, SetMarginMeasure
This is the default property of the eventSink object. It is used to connect or disconnect a script event handler to or from a specified event. See dynamic event binding for more information.
eventSink.handler(sEventName) = EventHandler
or
eventSink(sEventName) = EventHandler
or
eventSink(sEventName) = null
This is a read/write property. EventHandler can be either the string name of a script function or a direct function reference. null is used to disconnect the event hander.
sink("StatusTextChange") = onStatusTextChange
function onStatusTextChange(Text) { /* handling code */ }
Specify the event source object passed to NewEventSink. See dynamic event binding for more information.
This is a read-only property.
Specify the context value assigned to the eventSink object with NewEventSink. See dynamic event binding for more information.
This is a read-only property.
Creates a new event sink for a given object for dynamic event binding. To handle an event, a script handler must be assigned to the sink with the handler property. An optional context value can be passed to be available at the event handler when the event occurs.
eventSink = factory.NewEventSink(src[, ctx])
Parameter Description src (Object) the object to handle events from ctx (Any type) optional context value
Returns a new eventSink object. At event time the object is available to the script handler via implicit this (JScript) or me (VBScript) reference.
var browser = new ActiveXObject("InternetExplorer.Application")
var sink = factory.NewEventSink(browser)
sink("StatusTextChange") = onStatusTextChange
sink("NavigateComplete2") = onNavigateComplete2
sink("DocumentComplete") = onDocumentComplete
sink("OnQuit") = onQuit
browser.Navigate2("http://www.meadroid.com")
sink.Wait()
// ...
factory.Shutdown()
// handlers
function onStatusTextChange(Text) { /* handling code */ }
function onNavigateComplete2(pDisp, URL) { /* handling code */ }
function onDocumentComplete(pDisp, URL) { this.CancelWait() }
function onQuit() { this.Unadvise() }
eventSink, handler, src, ctx, Wait, CancelWait, Unadvise, Shutdown
Suspend (sleeps) the script execution for a specified timeout or until CancelWait is called. Events are serviced during sleep.
object.Wait([timeout])
Parameter Description timeout (Number) the optional timeout in milliseconds, -1 by default means to sleep until CancelWait is called.
Returns true if the sleep was timed out.
var browser = new ActiveXObject("InternetExplorer.Application")
var sink = factory.NewEventSink(browser)
sink("DocumentComplete") = onDocumentComplete
sink("OnQuit") = onQuit
browser.Navigate2("http://www.meadroid.com")
sink.Wait()
// ...
factory.Shutdown()
// handlers
function onDocumentComplete(pDisp, URL) { this.CancelWait() }
function onQuit() { this.Unadvise() }
Cancels the pending sleep (that is, the active Wait call).
object.CancelWait()
var browser = new ActiveXObject("InternetExplorer.Application")
var sink = factory.NewEventSink(browser)
sink("StatusTextChange") = onStatusTextChange
sink("NavigateComplete2") = onNavigateComplete2
sink("DocumentComplete") = onDocumentComplete
sink("OnQuit") = onQuit
browser.Navigate2("http://www.meadroid.com")
sink.Wait()
// ...
factory.Shutdown()
// handlers
function onStatusTextChange(Text) { /* handling code */ }
function onNavigateComplete2(pDisp, URL) { /* handling code */ }
function onDocumentComplete(pDisp, URL) { this.CancelWait() }
function onQuit() { this.Unadvise() }
Disconnects (unadvises) the eventSink object from its event source.
eventSink.Unadvise()
var browser = new ActiveXObject("InternetExplorer.Application")
var sink = factory.NewEventSink(browser)
sink("OnQuit") = onQuit
browser.Navigate2("http://www.meadroid.com")
sink.Wait()
// handlers
function onQuit() { this.Unadvise() }
The clean-up method for ScriptX. Should be called in cases where a dynamically created ScriptX object is no longer being used. All active event sinks get disconnected.
factory.Shutdown()
Checks whether or not the remote object is shut down. E.g. this can be a pop-up HTML window.
closed = factory.IsClosed(obj)
Parameter Description obj (Object) the remote object to check.
function IsWindowClosed(popup) {
return !popup || factory.IsClosed(popup) || popup.closed;
}
Invokes a native look & feel modal HTML dialog. See DHTML dialogs for more information and an example.
result = factory.ShowHtmlDialog(url, argIn[, options])
Parameter Description url (String) the URL of HTML page to be a dialog argIn (Any type) input parameter to reference within dialog options (String) optional features. See showModalDialog» on MSDN.
The alias for the Print method (for compatibility reasons).
Prints the specified frame using the current printing settings. See HTML Printing for more information and examples.
printing.Print([prompt[, frameOrWindow]])
Parameter Description prompt (Bool) whether or not to prompt frameOrWindow (Object) optional HTML frame or window» to print. By default, the hosting window is printed
Returns false if a user cancels the printing.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, SetPageRange, PrintHTML, SetMarginMeasure
Prints the specified URL using the current printing settings. To use this method, a publishing license» is required. See HTML Printing for more information and examples. This method is asynchronous. It returns before the HTML document is downloaded and printed.
PrintHTML may be used to organize a printing queue in a separate process, in which case the current window printing settings are kept unchanged; the download and print-out is queued and will be processed even if the calling window is closed. See OwnQueue for more details.
printing.PrintHTML(url[, useDefault = false])
Parameter Description url (String) URL to print useDefault (Bool) directs the use of default settings to bypass hidden Page Setup and Print dialogs.
WSH» script (JScript):
var factory = new ActiveXObject("ScriptX.Factory") factory.printing.PrintHTML("http://msdn.microsoft.com/workshop/author/script/dhtmlprint.asp")ASP page (VBScript):
<% set factory = CreateObject("ScriptX.Factory") factory.printing.PrintHTML "http://localhost/orders/order.asp?number=" & Request.Form("number") set factory = nothing %>
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, SetPageRange, Print, SetMarginMeasure, PrintXML, IsSpooling, EnumPrinters, OwnQueue
Sets the units of measure for print-out margins. To use this method, a publishing license» is required. See HTML Printing for more information and examples.
printing.SetMarginMeasure(units)
Parameter Description units (Number) 1 stands for millimeters, 2 for inches.
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, SetMarginMeasure, Print, PrintHTML
Sets the page selection to print. To use this method, a publishing license» is required. See HTML Printing for more information and examples.
printing.SetPageRange(selectionOnly[, from, to])
Parameter Description selectionOnly (Bool) print the highlighted HTML selection only from (Number) print from the page, 1-based. Use 0 to print all pages to (Number) print to the page, 1-based
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, SetMarginMeasure, Print, PrintHTML
Retrieves the versioning information of a specified component.
factory.GetComponentVersion(class, a, b, c, d)
Parameter Description class (String) either class name or GUID a, b, c, d (Number) variables to receive four digit version info
' VBScript dim a, b, c, d on error resume next factory.GetComponentVersion "msxml", a, b, c, d error = Err.Number on error goto 0 if error = 0 then alert "msxml version: " & a & "." & b & "." & c & "." & d
Creates a single-dimensional SafeArray (vector) of a specified size. See SafeArrays for more information and an example.
vec = js.Vec(size)
Parameter Description size (Number) number of elements in new vector
Returns the value of a SafeArray type.
VecFill, VecCopy, VecFromArray, VecGetSize, VecResize, VecPut, VecGet
Creates a one-dimensional SafeArray (vector) containing the specified elements. See SafeArrays for more information and an example.
vec = js.VecFill(elem1[, elem2[, ...]])
Parameter Description elem1...elemN (Any type) elements to fill the vector with
Returns the value of a SafeArray type.
Vec, VecCopy, VecFromArray, VecGetSize, VecResize, VecPut, VecGet
Creates a copy of a specified one-dimensional SafeArray (vector). See SafeArrays for more information and an example.
vec = js.VecCopy(srcVec)
Parameter Description srcVec (SafeArray) source vector to make a copy of
Returns the value of a SafeArray type.
Vec, VecFill, VecFromArray, VecGetSize, VecResize, VecPut, VecGet
Creates a one-dimensional SafeArray (vector) from a JScript array. See SafeArrays for more information and an example.
vec = js.VecFromArray(array)
Parameter Description array (Array) a source JScript array
Returns the value of a SafeArray type.
Vec, VecFill, VecCopy, VecGetSize, VecResize, VecPut, VecGet
Retrieves the size of specified one-dimensional SafeArray (vector). See SafeArrays for more information and example.
size = js.VecGetSize(vec)
Parameter Description vec (SafeArray) vector
Returns the size of the vector.
Vec, VecFill, VecCopy, VecFromArray, VecResize, VecPut, VecGet
Changes the size of a specified one-dimensional SafeArray (vector). See SafeArrays for more information and an example.
js.VecResize(vec, newSize)
Parameter Description vec (SafeArray) vector newSize (Number) new size of the vector
Vec, VecFill, VecCopy, VecFromArray, VecGetSize, VecPut, VecGet
Puts the element at the specified position of a one-dimensional SafeArray (vector). See SafeArrays for more information and an example.
js.VecPut(vec, pos, elem)
Parameter Description vec (SafeArray) vector pos (Number) position elem (Any type) element to put at the position
Retrieves the element at the specified position of a one-dimensional SafeArray (vector). See SafeArrays for more information and example.
elem = js.VecGet(vec, pos)
Parameter Description vec (SafeArray) vector pos (Number) position
Returns the element at the specified position.
Formats the data according to the corresponding format specification. See Formatting for more information and an example.
string = js.Format(strFormat[, param1[, param2[, ...]]])
Parameter Description strFromat (String) the format-control specification. See remarks below param1...param2 (Type as specifed at strFromat) paramters to format
The format-control string contains format specifications that determine the output format for the arguments following the strFromat parameter. Format specifications, discussed below, always begin with a percent sign (%). If a percent sign is followed by a character that has no meaning as a format field, the character is not formatted (for example, %% produces a single percent-sign character).
The format-control string is read from left to right. When the first format specification (if any) is encountered, it causes the value of the first argument after the format-control string to be converted and copied to the output buffer according to the format specification. If there are more arguments than format specifications, the extra arguments are ignored. If there are not enough arguments for all of the format specifications, the results are undefined.
A format specification has the following form:
%[-][#][0][width][.precision]type
Each field is a single character or a number signifying a particular format option. The type characters that appear after the last optional format field determine whether the associated argument is interpreted as a character, a string, or a number. The simplest format specification contains only the percent sign and a type character (for example, %s). The optional fields control other aspects of the formatting. Following are the optional and required fields and their meanings:
Field Meaning – Pad the output with blanks or zeros to the right to fill the field width, justifying output to the left. If this field is omitted, the output is padded to the left, justifying it to the right. # Prefix hexadecimal values with 0x (lowercase) or 0X (uppercase). 0 Pad the output value with zeros to fill the field width. If this field is omitted, the output value is padded with blank spaces. width Copy the specified minimum number of characters to the output buffer. The width field is a nonnegative integer. The width specification never causes a value to be truncated; if the number of characters in the output value is greater than the specified width, or if the width field is not present, all characters of the value are printed, subject to the precision specification. .precision For numbers, copy the specified minimum number of digits to the output buffer. If the number of digits in the argument is less than the specified precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds the specified precision. If the specified precision is 0 or omitted entirely, or if the period (.) appears without a number following it, the precision is set to 1. For strings, copy the specified maximum number of characters to the output buffer. type Output the corresponding argument as a character, a string, or a number. This field can be any of the following character sequences:
Sequence Insert C A single character. d A signed decimal integer argument. This sequence is equivalent to the i sequence. i A signed decimal integer. This sequence is equivalent to the d sequence. ls, lS A string. u An unsigned integer argument. x, X An unsigned hexadecimal integer in lowercase or uppercase.
Returns the formatted string.
Formatting functions which match those of VBScript: Format, FormatCurrency», FormatDateTime», FormatNumber», FormatPercent». They require the newer OLE Automation binaries to be available. See Formatting for more information and example.
Allows JScript to call a method of an ActiveX object that takes a parameter by reference. See Invoke 'ByRef' for more information.
value = js.InvokeByRef(object, method, argArray)
Parameter Description object (Object) object on which to call the method method (String) method to call argArray (Array) JScript array of arguments
Returns the same result as a direct object.method(...) call.
// pack params to "args" array
args = new Array("msxml", 0, 0, 0, 0)
// call the "GetComponentVersion" method on "factory" object
factory.js.InvokeByRef(factory, "GetComponentVersion", args)
alert("MSXML Version: "+args[1]+"."+args[2]+"."+args[3]+"."+args[4])
Allows JScript to call a method of an ActiveX object that takes a parameter by reference, and handle a possible failure case. See Invoke 'ByRef' for more information.
error = js.InvokeByRefResult(object, method, argArray)
Parameter Description object (Object) object on which to call the method method (String) method to call argArray (Array) JScript array of arguments
Returns the error code number of an object.method(...) call. Zero means the call has succeeded. The invocation result value (if applicable) is available as argArray.value.
// pack params to "args" array
args = new Array("msxml", 0, 0, 0, 0)
// call the "GetComponentVersion" method on "factory" object
error = factory.js.InvokeByRefResult(factory, "GetComponentVersion", args)
if ( error == 0 )
alert("MSXML Version: "+args[1]+"."+args[2]+"."+args[3]+"."+args[4])
else
alert("Error: "+error)
Plays a waveform sound. The waveform sound for each sound type is identified by an entry in the [sounds] section of the registry.
factory.MessageBeep([type])
Parameter Description type (Number) Specifies the sound type, as identified by an entry in the [sounds] section of the registry. This parameter can be one of the following values:
Value Sound -1 Standard beep using the computer speaker 0x00000040 SystemAsterisk 0x00000030 SystemExclamation 0x00000010 SystemHand 0x00000020 SystemQuestion 0x00000000 SystemDefault
Creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons.
result = factory.MessageBeep(text[, caption[, type]])
Parameter Description text (String) the message to display caption (String) message box caption type (Number) Specifies a set of bit flags that determine the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags. Specify one of the following flags to indicate the buttons contained in the message box:
Value Sound 0x00000000 The message box contains one push button: OK. This is the default 0x00000001 The message box contains two push buttons: OK and Cancel 0x00000004 The message box contains two push buttons: Yes and No 0x00000003 The message box contains three push buttons: Yes, No, and Cancel 0x00000030 An exclamation-point icon appears in the message box 0x00000040 An icon consisting of a lowercase letter i in a circle appears in the message box 0x00000010 A stop-sign icon appears in the message box 0x00010000 The message box becomes the foreground window 0x00040000 The message box is created as topmost window
The return value is one of the following menu-item values:
Value Meaning 3 Abort button was selected. 2 Cancel button was selected. 7 No button was selected. 1 OK button was selected. 6 Yes button was selected.
Notifies the caller about the completion of an HTML frame or window download.
factory.OnDocumentComplete(frameOrWindow, callback)
Parameter Description frameOrWindow (Object) frame or window object loading HTML content callback (Object) references to JScript function object to be called upon download completition
var child = open("child.htm")
function onChildLoad() {
alert("Window loaded: "+child.document.title)
}
factory.OnDocumentComplete(child, onChildLoad)
Prints an XSL-bound XML file specified by URL using the current printing settings. To use this method, a publishing license» is required. This asynchronous method requires Internet Explorer 5. It returns before the XML document is downloaded and printed. See HTML Printing for more information and examples.
printing.PrintXML(url[, useDefault = false])
Parameter Description url (String) URL to print useDefault (Bool) directs the use of default settings to bypass hidden Page Setup and Print dialogs.
WSH» script (JScript):
var factory = new ActiveXObject("ScriptX.Factory") factory.printing.PrintXML("http://msdn.microsoft.com/workshop/author/script/dhtmlprint.xml")ASP page (VBScript):
<% set factory = CreateObject("ScriptX.Factory") factory.printing.PrintXML("http://localhost/orders/order.asp?number=" & Request.Form("number") set factory = nothing %>
header, footer, portrait, leftMargin, rightMargin, topMargin, bottomMargin, paperSize, paperSource, copies, collate, printer, fontSize, SetPageRange, Print, SetMarginMeasure, OwnQueue
Checks if there are any outstanding downloads in the queue created by PrintHTML or PrintXML calls. Before quitting, an application might like to check that asynchronous downloads are complete and spooled. The onbeforeunload» event is suitable for that.
isSpooling = printing.IsSpooling()
Returns a boolean value indicating whether or not there are still outstanding downloads to be printed
<script>
var g_spooling = false;
function PrintAllDocs() {
factory.printing.portrait = false;
factory.printing.PrintXML(src1);
factory.printing.PrintXML(src2);
g_spooling = true;
setTimer("checkSpooling()", 3000);
}
function CheckSpooling() {
g_spooling = factory.printing.IsSpooling();
if ( !g_spooling ) window.close()
}
function window.onbeforeclose() {
if ( g_spooling ) return "The documents are still being printed!";
}
</script>
Enumerates locally-available printers. To use this method, a publishing license» is required.
printerName = printing.EnumPrinters(index)
Parameter Description index (Number) Zero-based index of the printer. Increment this value for each new EnumPrinters call
Returns the string name of the next printer. An empty value means the enumeration is over.
<script>
function window.onload() {
for ( i = 0; str = factory.printing.EnumPrinters(i); i++ )
alert("Printer name: "+str);
}
</script>
Returns the name of the default printer (if any). To use this method, a publishing license» is required.
printerName = printing.DefaultPrinter()
Enumerates active jobs on the given printer. To use this method, a publishing license» is required.
var jobName = {}
status = printing.EnumJobs(printerName, index, jobName)
Parameter Description printerName (String) printer name to enumerate the jobs on index (Number) Zero-based index of the job. Increment this value for each new EnumJobs call for given printerName jobName (Object) obtains a name of the job (available as jobName[0])
Returns the current status of the job. The bits have the following meaning:
Meaning Value JOB_STATUS_PAUSED 0x00000001 JOB_STATUS_ERROR 0x00000002 JOB_STATUS_DELETING 0x00000004 JOB_STATUS_SPOOLING 0x00000008 JOB_STATUS_PRINTING 0x00000010 JOB_STATUS_OFFLINE 0x00000020 JOB_STATUS_PAPEROUT 0x00000040 JOB_STATUS_PRINTED 0x00000080 JOB_STATUS_DELETED 0x00000100 JOB_STATUS_BLOCKED_DEVQ 0x00000200 JOB_STATUS_USER_INTERVENTION 0x00000400 JOB_STATUS_RESTART 0x00000800
<script>
function window.onload() {
for ( i = 0; str = factory.printing.EnumPrinters(i); i++ )
alert("Printer name: "+str);
}
</script>
OwnQueue is used to organize a printing queue in a separate process, in which case current window printing settings are kept unchanged; the download and print-out is queued with PrintHTML or PrintXML and will be processed even if the calling window is closed. To use this method, a publishing license» is required.
OwnQueue should be called before any PrintHTML or PrintXML commands.
Note: because a hidden Win32 process is created to serve the queue, the current page HTTP context (including possible login, authentication or SSL context) is invisible to it.
printing.OwnQueue()
<script>
function OutputHtml(html) {
idOutput.insertAdjacentHTML("BeforeEnd", html);
idOutput.scrollIntoView(false);
}
function EnumAll() {
OutputHtml("Default printer: <b>"+factory.printing.DefaultPrinter()+"</b><br>");
for ( i = 0; name = factory.printing.EnumPrinters(i); i++ ) {
OutputHtml("Printer: <b>"+name+"</b><br>Job count: "+factory.printing.GetJobsCount(name)+"<br>");
var jobName = new Object;
for ( j = 0; status = factory.printing.EnumJobs(name, j, jobName); j++ )
OutputHtml("Job: <b>"+jobName[0]+"</b>Status: "+new Number(status).toString(16)+"<br>");
}
}
function window.onload() {
EnumAll();
}
</script>
<p><small id=idOutput></small>
Returns the units of measure for print-out margins. To use this method, a publishing license» is required.
units = printing.GetMarginMeasure()
Returns the system default units of measure. 1 stands for millimeters, 2 for inches.