Class HTMLDocument
- All Implemented Interfaces:
Serializable,Cloneable,org.htmlunit.corejs.javascript.ConstProperties,org.htmlunit.corejs.javascript.debug.DebuggableObject,org.htmlunit.corejs.javascript.Scriptable,org.htmlunit.corejs.javascript.SymbolScriptable
HTMLDocument.- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate static final org.apache.commons.logging.Logprivate final StringBuilderThe buffer that will be used for calls to document.write().private booleanFields inherited from class org.htmlunit.javascript.host.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODEFields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONSTFields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappendChild(Object childObject) Adds a DOM node to the node.(package private) static booleancanAlreadyBeParsed(String content) Indicates if the content is a well formed HTML snippet that can already be parsed to be added to the DOM.voidclose()JavaScript functionclose.private static StringconcatArgsAsString(Object[] args) Converts the arguments to strings and concatenate them.createAttribute(String attributeName) Creates a new HTML attribute with the specified name.booleandispatchEvent(Event event) Dispatches an event into the event system (standards-conformant browsers only).elementFromPoint(int x, int y) Returns the element for the specified x coordinate and the specified y coordinate.Returns the value of theactiveElementproperty.Returns the Base URI as a string.Returns thecookieproperty.private static HTMLDocumentgetDocument(org.htmlunit.corejs.javascript.Scriptable thisObj) Returns the current document instance, usingthisObjas a hint.Gets the JavaScript propertydocumentElementfor the document.Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.getElementById(String id) Returns the element with the specified ID, ornullif that element could not be found.getElementsByClassName(String className) Returns all the descendant elements with the specified class name.getElementsByName(String elementName) Returns all HTML elements that have anameattribute with the specified value.getHead()Returns this document'sheadelement.private ObjectgetItComputeElements(HtmlPage page, String name, boolean alsoFrames) (package private) HtmlElementGets the node that is the last one when exploring following nodes, depth-first.getPage()Returns the HTML page that this document is modeling.Returns the current selection.getTitle()Returns this document's title.protected ObjectgetWithPreemption(String name) Calls todocument.XYZshould first look at elements namedXYZbefore using standard functions.booleanhasFocus()Returnsfalseif the active element in the document has no focus;trueif the active element in the document has focus.private voidCloses the document implicitly, i.e.voidJavaScript constructor.JavaScript function "open".private voidvoidAdds a cookie, as long as cookies are enabled.voidsetExecutingDynamicExternalPosponed(boolean executing) This a hack!!! A cleaner way is welcome.voidSets this document's title.protected voidJavaScript function "write".static voidwrite(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) JavaScript function "write" may accept a variable number of arguments.static voidwriteln(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) JavaScript function "writeln" may accept a variable number of arguments.Methods inherited from class org.htmlunit.javascript.host.dom.Document
adoptNode, captureEvents, clear, contains, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEvent, createNodeIterator, createNSResolver, createProcessingInstruction, createRange, createTextNode, createTreeWalker, evaluate, execCommand, forceDocumentMode, generateBlobUrl, getAlinkColor, getAll, getAnchors, getApplets, getBgColor, getBody, getCharacterSet, getCharset, getChildElementCount, getChildren, getCompatMode, getContentType, getCurrentScript, getDefaultView, getDesignMode, getDoctype, getDocumentMode, getDocumentURI, getDomain, getElementsByTagName, getElementsByTagNameNS, getEmbeds, getFgColor, getFirstElementChild, getFonts, getForms, getHidden, getImages, getImplementation, getInputEncoding, getLastElementChild, getLastModified, getLinkColor, getLinks, getLocation, getOnabort, getOnafterscriptexecute, getOnauxclick, getOnbeforecopy, getOnbeforecut, getOnbeforepaste, getOnbeforescriptexecute, getOnblur, getOncancel, getOncanplay, getOncanplaythrough, getOnchange, getOnclick, getOnclose, getOncontextmenu, getOncopy, getOncuechange, getOncut, getOndblclick, getOndrag, getOndragend, getOndragenter, getOndragleave, getOndragover, getOndragstart, getOndrop, getOndurationchange, getOnemptied, getOnended, getOnerror, getOnfocus, getOngotpointercapture, getOninput, getOninvalid, getOnkeydown, getOnkeypress, getOnkeyup, getOnload, getOnloadeddata, getOnloadedmetadata, getOnloadstart, getOnlostpointercapture, getOnmousedown, getOnmouseenter, getOnmouseleave, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getOnmousewheel, getOnmozfullscreenchange, getOnmozfullscreenerror, getOnpaste, getOnpause, getOnplay, getOnplaying, getOnpointercancel, getOnpointerdown, getOnpointerenter, getOnpointerleave, getOnpointerlockchange, getOnpointerlockerror, getOnpointermove, getOnpointerout, getOnpointerover, getOnpointerup, getOnprogress, getOnratechange, getOnreadystatechange, getOnreset, getOnresize, getOnscroll, getOnsearch, getOnseeked, getOnseeking, getOnselect, getOnselectionchange, getOnselectstart, getOnstalled, getOnsubmit, getOnsuspend, getOntimeupdate, getOntoggle, getOnvolumechange, getOnwaiting, getOnwebkitfullscreenchange, getOnwebkitfullscreenerror, getOnwheel, getPlugins, getReadyState, getReferrer, getRootElement, getScripts, getStyleSheets, getURL_js, getVlinkColor, getXmlEncoding, getXmlVersion, importNode, isXmlStandalone, queryCommandEnabled, queryCommandSupported, querySelector, querySelectorAll, releaseCapture, releaseEvents, resolveBlobUrl, revokeBlobUrl, setAlinkColor, setBgColor, setBody, setCurrentScript, setDesignMode, setDomain, setFgColor, setLinkColor, setLocation, setOnabort, setOnafterscriptexecute, setOnauxclick, setOnbeforecopy, setOnbeforecut, setOnbeforepaste, setOnbeforescriptexecute, setOnblur, setOncancel, setOncanplay, setOncanplaythrough, setOnchange, setOnclick, setOnclose, setOncontextmenu, setOncopy, setOncuechange, setOncut, setOndblclick, setOndrag, setOndragend, setOndragenter, setOndragleave, setOndragover, setOndragstart, setOndrop, setOndurationchange, setOnemptied, setOnended, setOnerror, setOnfocus, setOngotpointercapture, setOninput, setOninvalid, setOnkeydown, setOnkeypress, setOnkeyup, setOnload, setOnloadeddata, setOnloadedmetadata, setOnloadstart, setOnlostpointercapture, setOnmousedown, setOnmouseenter, setOnmouseleave, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnmousewheel, setOnmozfullscreenchange, setOnmozfullscreenerror, setOnpaste, setOnpause, setOnplay, setOnplaying, setOnpointercancel, setOnpointerdown, setOnpointerenter, setOnpointerleave, setOnpointerlockchange, setOnpointerlockerror, setOnpointermove, setOnpointerout, setOnpointerover, setOnpointerup, setOnprogress, setOnratechange, setOnreadystatechange, setOnreset, setOnresize, setOnscroll, setOnsearch, setOnseeked, setOnseeking, setOnselect, setOnselectionchange, setOnselectstart, setOnstalled, setOnsubmit, setOnsuspend, setOntimeupdate, setOntoggle, setOnvolumechange, setOnwaiting, setOnwebkitfullscreenchange, setOnwebkitfullscreenerror, setOnwheel, setVlinkColor, setWindowMethods inherited from class org.htmlunit.javascript.host.dom.Node
after, append, before, cloneNode, compareDocumentPosition, getAttributes, getChildNodes, getFirstChild, getJavaScriptNode, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParent, getParentElement, getParentNode, getPrefix, getPreviousSibling, getRootNode, getTextContent, hasAttributes, hasChildNodes, insertBefore, insertBeforeImpl, isEqualNode, isSameNode, normalize, prepend, remove, removeChild, replaceChild, replaceChildren, replaceWith, setNodeValue, setTextContentMethods inherited from class org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandlerMethods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromiseMethods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
writeBuilder_
The buffer that will be used for calls to document.write(). -
writeInCurrentDocument_
private boolean writeInCurrentDocument_ -
closePostponedAction_
private boolean closePostponedAction_ -
executionExternalPostponed_
private boolean executionExternalPostponed_
-
-
Constructor Details
-
HTMLDocument
public HTMLDocument()The constructor.
-
-
Method Details
-
jsConstructor
public void jsConstructor()JavaScript constructor.- Overrides:
jsConstructorin classDocument
-
getDomNodeOrDie
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.- Overrides:
getDomNodeOrDiein classHtmlUnitScriptable- Returns:
- the DOM node
-
getPage
Returns the HTML page that this document is modeling. -
write
public static void write(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) JavaScript function "write" may accept a variable number of arguments.- Parameters:
context- the JavaScript contextscope- the scopethisObj- the scriptableargs- the arguments passed into the methodfunction- the function- See Also:
-
concatArgsAsString
Converts the arguments to strings and concatenate them.- Parameters:
args- the JavaScript arguments- Returns:
- the string concatenation
-
writeln
public static void writeln(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) JavaScript function "writeln" may accept a variable number of arguments.- Parameters:
context- the JavaScript contextscope- the scopethisObj- the scriptableargs- the arguments passed into the methodfunction- the function- See Also:
-
getDocument
Returns the current document instance, usingthisObjas a hint.- Parameters:
thisObj- a hint as to the current document (may be the prototype when function is used without "this")- Returns:
- the current document instance
-
setExecutingDynamicExternalPosponed
public void setExecutingDynamicExternalPosponed(boolean executing) This a hack!!! A cleaner way is welcome. Handle a case where document.write is simply ignored. See HTMLDocumentWrite2Test.write_fromScriptAddedWithAppendChild_external.- Parameters:
executing- indicates if executing or not
-
write
JavaScript function "write".See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for a good description of the semantics of open(), write(), writeln() and close().
- Parameters:
content- the content to write
-
scheduleImplicitClose
private void scheduleImplicitClose() -
canAlreadyBeParsed
Indicates if the content is a well formed HTML snippet that can already be parsed to be added to the DOM.- Parameters:
content- the HTML snippet- Returns:
falseif it not well formed
-
getLastHtmlElement
Gets the node that is the last one when exploring following nodes, depth-first.- Parameters:
node- the node to search- Returns:
- the searched node
-
getCookie
Returns thecookieproperty. -
setCookie
Adds a cookie, as long as cookies are enabled.- Parameters:
newCookie- in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure]- See Also:
-
open
JavaScript function "open".See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for a good description of the semantics of open(), write(), writeln() and close().
- Parameters:
url- when a new document is opened, url is a String that specifies a MIME type for the document. When a new window is opened, url is a String that specifies the URL to render in the new windowname- the namefeatures- the featuresreplace- whether to replace in the history list or no- Returns:
- a reference to the new document object.
- See Also:
-
close
JavaScript functionclose.See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for a good description of the semantics of open(), write(), writeln() and close().
- Overrides:
closein classDocument- Throws:
IOException- if an IO problem occurs
-
getDocumentElement
Gets the JavaScript propertydocumentElementfor the document.- Overrides:
getDocumentElementin classDocument- Returns:
- the root node for the document
-
implicitCloseIfNecessary
private void implicitCloseIfNecessary()Closes the document implicitly, i.e. flushes thedocument.writebuffer (IE only). -
appendChild
Adds a DOM node to the node.- Overrides:
appendChildin classNode- Parameters:
childObject- the node to add to this node- Returns:
- the newly added child node
-
getElementById
Returns the element with the specified ID, ornullif that element could not be found.- Overrides:
getElementByIdin classDocument- Parameters:
id- the ID to search for- Returns:
- the element, or
nullif it could not be found
-
getElementsByClassName
Returns all the descendant elements with the specified class name.- Overrides:
getElementsByClassNamein classDocument- Parameters:
className- the name to search for- Returns:
- all the descendant elements with the specified class name
- See Also:
-
getElementsByName
Returns all HTML elements that have anameattribute with the specified value.Refer to The DOM spec for details.
- Overrides:
getElementsByNamein classDocument- Parameters:
elementName- - value of thenameattribute to look for- Returns:
- all HTML elements that have a
nameattribute with the specified value
-
getWithPreemption
Calls todocument.XYZshould first look at elements namedXYZbefore using standard functions.Called by
HtmlUnitScriptable.get(String, Scriptable)to allow retrieval of the property before the prototype chain is searched.IMPORTANT: This method is invoked *very* often by Rhino. If you override this method, the implementation needs to be as fast as possible!
- Overrides:
getWithPreemptionin classHtmlUnitScriptable- Parameters:
name- the property name- Returns:
Scriptable.NOT_FOUNDif not found
-
getIt
-
getItComputeElements
-
getHead
Returns this document'sheadelement. -
getTitle
Returns this document's title. -
setTitle
Sets this document's title. -
getActiveElement
Returns the value of theactiveElementproperty.- Overrides:
getActiveElementin classDocument- Returns:
- the value of the
activeElementproperty - See Also:
-
hasFocus
public boolean hasFocus()Returnsfalseif the active element in the document has no focus;trueif the active element in the document has focus. -
dispatchEvent
Dispatches an event into the event system (standards-conformant browsers only). See the Gecko DOM reference for more information.- Overrides:
dispatchEventin classEventTarget- Parameters:
event- the event to be dispatched- Returns:
falseif at least one of the event handlers which handled the event calledpreventDefault;trueotherwise
-
getSelection
Returns the current selection.- Overrides:
getSelectionin classDocument- Returns:
- the current selection
-
createAttribute
Creates a new HTML attribute with the specified name.- Overrides:
createAttributein classDocument- Parameters:
attributeName- the name of the attribute to create- Returns:
- an attribute with the specified name
-
getBaseURI
Returns the Base URI as a string.- Overrides:
getBaseURIin classNode- Returns:
- the Base URI as a string
-
elementFromPoint
Returns the element for the specified x coordinate and the specified y coordinate. The current implementation always returns the <body> element.- Overrides:
elementFromPointin classDocument- Parameters:
x- the x offset, in pixelsy- the y offset, in pixels- Returns:
- the element for the specified x coordinate and the specified y coordinate
-