Document methods

The Document interface supports the following methods, in addition to those inherited from the DOMNode interface.

Activate  
Returns  No return value 
Description  Activates the specified Document object (the corresponding document becomes the active document, and is then also represented by the ActiveDocument object). The document must already be open. 
Usage 
JScript  Document_object.Activate();  
VBScript  Document_object.Activate 
Example 
// SoftQuad Script Language JSCRIPT:
// Store the object representing
// the active document
var doc = Application.ActiveDocument;
// Add a document; the new document automatically
// becomes the active document
Documents.Add(); 
// re-activate the original active document
doc.Activate(); 
 

Close([intSaveChanges=0])  
Returns  No return value 
Description 

Closes the document, and may save changes, depending on the value of intSaveChanges. The allowed values are:

  • 0: prompt the user to save changes (the default)
  • 1: save changes without prompting
  • 2: do not save changes

Note: Scripts using Application.Close should not be dragged-and-dropped or pasted into a document. Application.Close can be used in macros, but should be avoided in the special macros triggered by various events (for example, On_Document_Activate and On_Update_UI)

 
Usage 
JScript  Document_object.Close();  
VBScript  Document_object.Close 
Example 
// SoftQuad Script Language JSCRIPT:
Documents.Add(); // open a new document
ActiveDocument.Close(2); // close the new document 
 

createAttribute(strName) (Implements DOM
Returns  DOMAttr  
Description  Creates a DOMAttr object corresponding to the strName attribute. Not implemented; to insert an attribute, use the Selection.ContainerAttribute or Selection.ElementAttribute method.  

createComment(strData) (Implements DOM
Returns  DOMComment  
Description  Creates a DOMComment node containing the strData string. Not implemented; to insert a comment, use the Selection.InsertComment method. 

createElement(strName) (Implements DOM
Returns  DOMElement  
Description  Creates a DOMElement object corresponding to a strName element. Note that attributes can be specified directly on the returned object. Not implemented; to insert an element, use Selection.InsertElement, Selection.InsertElementWithRequired, or Selection.InsertWithTemplate

createEntityReference(strName) (Implements DOM
Returns  DOMEntityReference  
Description  Creates a DOMEntityReference object corresponding to a reference to the strName entity. Not implemented; to insert an entity reference, use Selection.InsertEntity

createProcessingInstruction(strTarget, strData) (Implements DOM
Returns  DOMProcessingInstruction  
Description  Creates a DOMProcessingInstruction node corresponding to a PI with the specified strTarget and strData strings. Not implemented. To insert a processing instruction, use the Selection.InsertProcessingInstruction method. 

createTextNode(strData) (Implements DOM
Returns  DOMText  
Description  Creates a DOMText node containing the string strData. Not implemented; to paste a string, use the Selection.PasteString method. 

getElementsByTagName(strTagName) (Implements DOM
Returns  DOMNodeList  
Description  Returns a DOMNodeList of DOMElement objects, representing all elements in the document with the element name strTagName. The special strTagName `*' matches all elements. 
Usage 
JScript  Document_object.getElementsByTagName("strTagName");  
VBScript  Document_object.getElementsByTagName("strTagName")  
Example 
// SoftQuad Script Language JSCRIPT:
var elemList;
var allElemList;
//get all "Title" elements  
elemList=ActiveDocument.getElementsByTagName("TITLE"); 
Application.Alert(elemList.length);
//get all elements in the document
allElemList=ActiveDocument.getElementsByTagName("*"); 
Application.Alert(allElemList.length);
 

Layout 
Returns  Boolean 
Description  Applies text layout (as specified in the Text Layout tab of the Customization editor) to the entire document. This method can be used only if the document is displayed in HTML Source view; Layout returns true if the document is in HTML Source view, and false otherwise. See also Selection.Layout
Usage 
JScript  Document_object.Layout();  
VBScript  Document_object.Layout 
Example 
// SoftQuad Script Language JSCRIPT:
// Format the entire document
if (ActiveDocument.ViewType == 2) {
   ActiveDocument.Layout();
}
 

Redo([intNumberOfTimes=1])  
Returns  Boolean 
Description  Redo the last intNumberOfTimes undone actions. The default action is to redo the last undone action. Returns true if the redo succeeds. 
Usage 
JScript  Document_object.Redo([number]);  
VBScript  Document_object.Redo([number]) 
Example 
// SoftQuad Script Language JSCRIPT:
ActiveDocument.Redo(); //redo the last undone action
 

Reload 
Returns   No return value 
Description  Reloads the specified document from the disk. The document must be open. Reload does not check if the document has been changed before reloading. 
Usage 
JScript  Document_object.Reload(); 
VBScript  Document_object.Reload 
Example 
// SoftQuad Script Language JSCRIPT:
if (Application.IsDocumentOpen(doc1)) {
   doc1.Reload();
}
 

Save  
Returns  No return value 
Description  Saves the specified document. 
Usage 
JScript  Document_object.Save();  
VBScript  Document_object.Save 

SaveAs([strFileName],[boolAddToRecentFiles=true])  
Returns  No return value 
Description  Saves the document, using the strFileName file name. If strFileName is not specified, the Save As dialog window will pop up. boolAddToRecentFiles determines whether the file will be added to the recent files area of the File menu. 
Usage 
JScript  Document_object.SaveAs([strFileName], [boolAddToRecentFiles]);  
VBScript  Document_object.SaveAs [[strFileName], [boolAddToRecentFiles]]  
Example 
' SoftQuad Script Language VBSCRIPT:
' Saves the active document as  "myFile.html"
' and adds a 
' reference to it in the Recent Files menu.
 
ActiveDocument.SaveAs "myFile.html", true 
 

ScrollToSelection  
Returns  Boolean 
Description  Scrolls the screen to the current selection. 
Usage 
JScript  Document_object.ScrollToSelection();  
VBScript  Document_object.ScrollToSelection 

Undo([intNumberOfTimes=1])  
Returns  Boolean 
Description  Undoes the previous intNumberOfTimes change(s) to the document. The default is to undo the last change. Returns true if the undo succeeds. 
Usage 
JScript  Document_object.Undo([intNumberOfTimes=1]);  
VBScript  Document_object.Undo([intNumberOfTimes]) 
Example 
// SoftQuad Script Language JSCRIPT:
ActiveDocument.Undo(); //undo the last action
 

UniqueAttributeValue(strPrefix, strAttributeName, [intNumber]) 
Returns  String 
Description  Returns a string that is not used as the value of any strAttributeName attribute in the active document. If strPrefix is such a string, it is returned. If not, the number 1 is appended to strPrefix and the test is repeated. The number is incremented until an unused value is found. If intNumber is specified then that value is used as the starting number instead of 1. A maximum of 100 tests are performed. If an unused value is not found then the null string is returned.  
Usage 
JScript  Document_object.UniqueAttributeValue("aPrefix", "attribName");  
VBScript  Document_object.UniqueAttributeValue("aPrefix", "attribName")  
Example 
// SoftQuad Script Language JSCRIPT:
// search for unique "STATUS" attribute
var temp;
temp=ActiveDocument.UniqueAttributeValue("S", "STATUS");
Application.Alert(temp);
 

Validate  
Returns  No return value 
Description  Validates the document, just as if the Validate Document command were chosen. A message will be displayed to the user. See also Document.IsValid, Selection.Validate, and Selection.IsValid
Usage 
JScript  Document_object.Validate();  
VBScript  Document_object.Validate  


Right arrow
Next Topic
Left arrow
Previous Topic
Table of contents
Table of Contents

Copyright © SoftQuad Software Inc. 1999