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 boolean
private boolean
private static final org.apache.commons.logging.Log
private final StringBuilder
The buffer that will be used for calls to document.write().private boolean
Fields 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_NODE
Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
Fields 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 boolean
canAlreadyBeParsed
(String content) Indicates if the content is a well formed HTML snippet that can already be parsed to be added to the DOM.void
close()
JavaScript functionclose
.private static String
concatArgsAsString
(Object[] args) Converts the arguments to strings and concatenate them.createAttribute
(String attributeName) Creates a new HTML attribute with the specified name.boolean
dispatchEvent
(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 theactiveElement
property.Returns the Base URI as a string.Returns thecookie
property.private static HTMLDocument
getDocument
(org.htmlunit.corejs.javascript.Scriptable thisObj) Returns the current document instance, usingthisObj
as a hint.Gets the JavaScript propertydocumentElement
for 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, ornull
if 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 aname
attribute with the specified value.getHead()
Returns this document'shead
element.private Object
getItComputeElements
(HtmlPage page, String name, boolean alsoFrames) (package private) HtmlElement
Gets 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 Object
getWithPreemption
(String name) Calls todocument.XYZ
should first look at elements namedXYZ
before using standard functions.boolean
hasFocus()
Returnsfalse
if the active element in the document has no focus;true
if the active element in the document has focus.private void
Closes the document implicitly, i.e.void
JavaScript constructor.JavaScript function "open".private void
void
Adds a cookie, as long as cookies are enabled.void
setExecutingDynamicExternalPosponed
(boolean executing) This a hack!!! A cleaner way is welcome.void
Sets this document's title.protected void
JavaScript function "write".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.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.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, setWindow
Methods 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, setTextContent
Methods inherited from class org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandler
Methods 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, setupRejectedPromise
Methods 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:
jsConstructor
in classDocument
-
getDomNodeOrDie
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.- Overrides:
getDomNodeOrDie
in 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, usingthisObj
as 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:
false
if 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 thecookie
property. -
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:
close
in classDocument
- Throws:
IOException
- if an IO problem occurs
-
getDocumentElement
Gets the JavaScript propertydocumentElement
for the document.- Overrides:
getDocumentElement
in classDocument
- Returns:
- the root node for the document
-
implicitCloseIfNecessary
private void implicitCloseIfNecessary()Closes the document implicitly, i.e. flushes thedocument.write
buffer (IE only). -
appendChild
Adds a DOM node to the node.- Overrides:
appendChild
in classNode
- Parameters:
childObject
- the node to add to this node- Returns:
- the newly added child node
-
getElementById
Returns the element with the specified ID, ornull
if that element could not be found.- Overrides:
getElementById
in classDocument
- Parameters:
id
- the ID to search for- Returns:
- the element, or
null
if it could not be found
-
getElementsByClassName
Returns all the descendant elements with the specified class name.- Overrides:
getElementsByClassName
in 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 aname
attribute with the specified value.Refer to The DOM spec for details.
- Overrides:
getElementsByName
in classDocument
- Parameters:
elementName
- - value of thename
attribute to look for- Returns:
- all HTML elements that have a
name
attribute with the specified value
-
getWithPreemption
Calls todocument.XYZ
should first look at elements namedXYZ
before 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:
getWithPreemption
in classHtmlUnitScriptable
- Parameters:
name
- the property name- Returns:
Scriptable.NOT_FOUND
if not found
-
getIt
-
getItComputeElements
-
getHead
Returns this document'shead
element. -
getTitle
Returns this document's title. -
setTitle
Sets this document's title. -
getActiveElement
Returns the value of theactiveElement
property.- Overrides:
getActiveElement
in classDocument
- Returns:
- the value of the
activeElement
property - See Also:
-
hasFocus
public boolean hasFocus()Returnsfalse
if the active element in the document has no focus;true
if 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:
dispatchEvent
in classEventTarget
- Parameters:
event
- the event to be dispatched- Returns:
false
if at least one of the event handlers which handled the event calledpreventDefault
;true
otherwise
-
getSelection
Returns the current selection.- Overrides:
getSelection
in classDocument
- Returns:
- the current selection
-
createAttribute
Creates a new HTML attribute with the specified name.- Overrides:
createAttribute
in 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:
getBaseURI
in 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:
elementFromPoint
in 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
-