Class Location

java.lang.Object
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.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class Location extends HtmlUnitScriptable
A JavaScript object for Location.
See Also:
  • Nested Class Summary

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

    org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private String
    The current hash; we cache it locally because we don't want to modify the page's URL and force a page reload each time this changes.
    private static final org.apache.commons.logging.Log
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final Method
     
    private static final String
     
    private Window
    The window which owns this location object.

    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
    Constructor
    Description
    Creates an instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Loads the new HTML document corresponding to the specified URL.
    private static String
     
    Returns the JavaScript default value of this object.
    Returns the hash portion of the location URL (the portion following the '#').
    private String
    getHash(boolean encoded)
     
    Returns the host portion of the location URL (the '[hostname]:[port]' portion).
    Returns the hostname portion of the location URL.
    Returns the location URL.
    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 '?').
    private URL
    Returns this location's current URL.
    void
    initialize(Window window, Page page)
    Initializes this Location.
    void
    Creates an instance.
    Returns the location URL.
    void
    reload(boolean force)
    Reloads the current page, possibly forcing retrieval from the server even if the browser cache contains the latest version of the document.
    void
    Reloads the window using the specified URL via a postponed action.
    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.
    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 '?').
    private void
    setUrl(URL url)
    Sets this location's URL, triggering a server hit and loading the resultant document into this location's window.

    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

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG

      private static final org.apache.commons.logging.Log LOG
    • UNKNOWN

      private static final String UNKNOWN
      See Also:
    • window_

      private Window window_
      The window which owns this location object.
    • methodAssign

      private static final Method methodAssign
    • methodReload

      private static final Method methodReload
    • methodReplace

      private static final Method methodReplace
    • methodToString

      private static final Method methodToString
    • getterHash

      private static final Method getterHash
    • setterHash

      private static final Method setterHash
    • getterHost

      private static final Method getterHost
    • setterHost

      private static final Method setterHost
    • getterHostname

      private static final Method getterHostname
    • setterHostname

      private static final Method setterHostname
    • getterHref

      private static final Method getterHref
    • setterHref

      private static final Method setterHref
    • getterOrigin

      private static final Method getterOrigin
    • getterPathname

      private static final Method getterPathname
    • setterPathname

      private static final Method setterPathname
    • getterPort

      private static final Method getterPort
    • setterPort

      private static final Method setterPort
    • getterProtocol

      private static final Method getterProtocol
    • setterProtocol

      private static final Method setterProtocol
    • getterSearch

      private static final Method getterSearch
    • setterSearch

      private static final Method setterSearch
    • hash_

      private String hash_
      The current hash; we cache it locally because we don't want to modify the page's URL and force a page reload each time this changes.
  • Constructor Details

    • Location

      public Location()
      Creates an instance.
  • Method Details

    • jsConstructor

      public void jsConstructor()
      Creates an instance.
    • initialize

      public void initialize(Window window, Page page)
      Initializes this Location.
      Parameters:
      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 location 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, possibly forcing retrieval from the server even if the browser cache contains the latest version of the document.
      Parameters:
      force - if true, force reload from server; otherwise, may reload from cache
      Throws:
      IOException - if there is a problem reloading the page
      See Also:
    • replace

      public void replace(String url) throws IOException
      Reloads the window using the specified URL via a postponed action.
      Parameters:
      url - the new URL to use to reload the window
      Throws:
      IOException - if loading the specified location fails
      See Also:
    • jsToString

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

      public String getHref()
      Returns the location URL.
      Returns:
      the location URL
      See Also:
    • setHref

      public void setHref(String newLocation) throws IOException
      Sets the location URL to an entirely new value.
      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:
    • getHash

      private String getHash(boolean encoded)
    • setHash

      public void setHash(String hash)
      Sets the hash portion of the location URL (the portion following the '#').
      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
    • decodeHash

      private static String decodeHash(String hash)
    • 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
      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, including the trailing ':'
      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:
    • getUrl

      private URL getUrl()
      Returns this location's current URL.
      Returns:
      this location's current URL
    • setUrl

      private void setUrl(URL url) throws IOException
      Sets this location's URL, triggering a server hit and loading the resultant document into this location's window.
      Parameters:
      url - This location's new URL
      Throws:
      IOException - if there is a problem loading the new location
    • getOrigin

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