Module org.htmlunit

Class Location

java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.Location
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class Location extends HtmlUnitScriptable
JavaScript host object for Location.
Author:
Mike Bowler, Michael Ottati, Marc Guillemot, Chris Erskine, Daniel Gredler, David K. Taylor, Ahmed Ashour, Ronald Brill, Frank Danek, Adam Afeltowicz, Atsushi Nakagawa, Lai Quang Duong, Kanoko Yamamoto
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction
  • Field Summary

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    isSealed

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Loads the new HTML document corresponding to the specified URL.
    Returns the JavaScript default value of this object.
    Returns the hash portion of the location URL (the portion following the #).
    Returns the host portion of the location URL (the [hostname]:[port] portion).
    Returns the hostname portion of the location URL.
    Returns the full URL of the current page.
    Returns the origin property.
    Returns the pathname portion of the location URL.
    Returns the port portion of the location URL.
    Returns the protocol portion of the location URL, including the trailing :.
    Returns the search portion of the location URL (the portion following the ?).
    void
    initialize(org.htmlunit.corejs.javascript.VarScope scope, Window window, Page page)
    Initializes this Location.
    static Location
    jsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr)
    Creates an instance of this object.
    Returns the location URL as a string.
    void
    reload(boolean force)
    Reloads the current page, optionally forcing retrieval from the server even if the browser cache contains the latest version of the document.
    void
    Loads the document at the specified URL, replacing the current entry in the session history so that the previous page cannot be reached via the back button.
    void
    Sets the hash portion of the location URL (the portion following the #).
    void
    setHash(String oldURL, String hash)
    Sets the hash portion of the location URL (the portion following the #).
    void
    setHash(String oldURL, String hash, boolean triggerHashChanged)
    INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
    Sets the hash portion of the location URL (the portion following the #).
    void
    Sets the host portion of the location URL (the [hostname]:[port] portion).
    void
    setHostname(String hostname)
    Sets the hostname portion of the location URL.
    void
    setHref(String newLocation)
    Sets the location URL to an entirely new value, navigating to the new page.
    void
    setPathname(String pathname)
    Sets the pathname portion of the location URL.
    void
    Sets the port portion of the location URL.
    void
    setProtocol(String protocol)
    Sets the protocol portion of the location URL.
    void
    setSearch(String search)
    Sets the search portion of the location URL (the portion following the ?).

    Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMaps

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.htmlunit.corejs.javascript.Scriptable

    get, getIds, has, has

    Methods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable

    get, has
  • Constructor Details

    • Location

      public Location()
  • Method Details

    • jsConstructor

      public static Location jsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr)
      Creates an instance of this object.
      Parameters:
      cx - the current context
      scope - the scope
      args - the constructor arguments
      ctorObj - the function object
      inNewExpr - whether invoked via new
      Returns:
      the new Location instance
    • initialize

      public void initialize(org.htmlunit.corejs.javascript.VarScope scope, Window window, Page page)
      Initializes this Location.
      Parameters:
      scope - the scope
      window - the window that this location belongs to
      page - the page that will become the enclosing page
    • getDefaultValue

      public Object getDefaultValue(Class<?> hint)
      Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.
      Specified by:
      getDefaultValue in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getDefaultValue in class HtmlUnitScriptable
      Parameters:
      hint - a hint as to the format of the default value (ignored in this case)
      Returns:
      the default value
    • assign

      public void assign(String url) throws IOException
      Loads the new HTML document corresponding to the specified URL.
      Parameters:
      url - the URL of the new HTML document to load
      Throws:
      IOException - if loading the specified location fails
      See Also:
    • reload

      public void reload(boolean force) throws IOException
      Reloads the current page, optionally forcing retrieval from the server even if the browser cache contains the latest version of the document.
      Parameters:
      force - if true, force reload from the server; otherwise, the browser may reload from cache
      Throws:
      IOException - if there is a problem reloading the page
      See Also:
    • replace

      public void replace(String url) throws IOException
      Loads the document at the specified URL, replacing the current entry in the session history so that the previous page cannot be reached via the back button.
      Parameters:
      url - the new URL to load
      Throws:
      IOException - if loading the specified location fails
      See Also:
    • jsToString

      public String jsToString()
      Returns the location URL as a string.
      Returns:
      the location URL
    • getHref

      public String getHref()
      Returns the full URL of the current page.
      Returns:
      the location URL
      See Also:
    • setHref

      public void setHref(String newLocation) throws IOException
      Sets the location URL to an entirely new value, navigating to the new page.
      Parameters:
      newLocation - the new location URL
      Throws:
      IOException - if loading the specified location fails
      See Also:
    • getSearch

      public String getSearch()
      Returns the search portion of the location URL (the portion following the ?).
      Returns:
      the search portion of the location URL
      See Also:
    • setSearch

      public void setSearch(String search) throws Exception
      Sets the search portion of the location URL (the portion following the ?).
      Parameters:
      search - the new search portion of the location URL
      Throws:
      Exception - if an error occurs
      See Also:
    • getHash

      public String getHash()
      Returns the hash portion of the location URL (the portion following the #).
      Returns:
      the hash portion of the location URL
      See Also:
    • setHash

      public void setHash(String hash)
      Sets the hash portion of the location URL (the portion following the #). This method does not cause a server hit.
      Parameters:
      hash - the new hash portion of the location URL
      See Also:
    • setHash

      public void setHash(String oldURL, String hash)
      Sets the hash portion of the location URL (the portion following the #).
      Parameters:
      oldURL - the old URL
      hash - the new hash portion of the location URL
    • setHash

      public void setHash(String oldURL, String hash, boolean triggerHashChanged)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Sets the hash portion of the location URL (the portion following the #).
      Parameters:
      oldURL - the old URL
      hash - the new hash portion of the location URL
      triggerHashChanged - option to disable event triggering
    • getHostname

      public String getHostname()
      Returns the hostname portion of the location URL.
      Returns:
      the hostname portion of the location URL
      See Also:
    • setHostname

      public void setHostname(String hostname) throws Exception
      Sets the hostname portion of the location URL.
      Parameters:
      hostname - the new hostname portion of the location URL
      Throws:
      Exception - if an error occurs
      See Also:
    • getHost

      public String getHost()
      Returns the host portion of the location URL (the [hostname]:[port] portion).
      Returns:
      the host portion of the location URL
      See Also:
    • setHost

      public void setHost(String host) throws Exception
      Sets the host portion of the location URL (the [hostname]:[port] portion).
      Parameters:
      host - the new host portion of the location URL
      Throws:
      Exception - if an error occurs
      See Also:
    • getPathname

      public String getPathname()
      Returns the pathname portion of the location URL.
      Returns:
      the pathname portion of the location URL
      See Also:
    • setPathname

      public void setPathname(String pathname) throws Exception
      Sets the pathname portion of the location URL.
      Parameters:
      pathname - the new pathname portion of the location URL
      Throws:
      Exception - if an error occurs
      See Also:
    • getPort

      public String getPort()
      Returns the port portion of the location URL.
      Returns:
      the port portion of the location URL, or an empty string if no port is specified
      See Also:
    • setPort

      public void setPort(String port) throws Exception
      Sets the port portion of the location URL.
      Parameters:
      port - the new port portion of the location URL
      Throws:
      Exception - if an error occurs
      See Also:
    • getProtocol

      public String getProtocol()
      Returns the protocol portion of the location URL, including the trailing :.
      Returns:
      the protocol portion of the location URL
      See Also:
    • setProtocol

      public void setProtocol(String protocol) throws Exception
      Sets the protocol portion of the location URL.
      Parameters:
      protocol - the new protocol portion of the location URL
      Throws:
      Exception - if an error occurs
      See Also:
    • getOrigin

      public String getOrigin()
      Returns the origin property.
      Returns:
      the origin property