Class URL

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.URL
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 URL extends HtmlUnitScriptable
A JavaScript object for URL.
See Also:
  • Field Details

    • url_

      private URL url_
  • Constructor Details

    • URL

      public URL()
      Creates an instance.
  • Method Details

    • jsConstructor

      public void jsConstructor(String url, Object base)
      Creates an instance.
      Parameters:
      url - a string representing an absolute or relative URL. If url is a relative URL, base is required, and will be used as the base URL. If url is an absolute URL, a given base will be ignored.
      base - a string representing the base URL to use in case url is a relative URL. If not specified, it defaults to ''.
    • createObjectURL

      public static String createObjectURL(Object fileOrBlob)
      The URL.createObjectURL() static method creates a DOMString containing a URL representing the object given in parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.
      Parameters:
      fileOrBlob - Is a File object or a Blob object to create a object URL for.
      Returns:
      the url
    • revokeObjectURL

      public static void revokeObjectURL(org.htmlunit.corejs.javascript.Scriptable objectURL)
      Parameters:
      objectURL - String representing the object URL that was created by calling URL.createObjectURL().
    • getHash

      public String getHash()
      Returns:
      hash property of the URL containing a '#' followed by the fragment identifier of the URL.
    • setHash

      public void setHash(String fragment) throws MalformedURLException
      Throws:
      MalformedURLException
    • getHost

      public String getHost()
      Returns:
      the host, that is the hostname, and then, if the port of the URL is nonempty, a ':', followed by the port of the URL.
    • setHost

      public void setHost(String host) throws MalformedURLException
      Throws:
      MalformedURLException
    • getHostname

      public String getHostname()
      Returns:
      the host, that is the hostname, and then, if the port of the URL is nonempty, a ':', followed by the port of the URL.
    • setHostname

      public void setHostname(String hostname) throws MalformedURLException
      Throws:
      MalformedURLException
    • getHref

      public String getHref()
      Returns:
      whole URL
    • setHref

      public void setHref(String href) throws MalformedURLException
      Throws:
      MalformedURLException
    • getOrigin

      public Object getOrigin()
      Returns:
      the origin
    • getSearchParams

      public URLSearchParams getSearchParams()
      Returns:
      a URLSearchParams object allowing access to the GET decoded query arguments contained in the URL.
    • getPassword

      public String getPassword()
      Returns:
      the password specified before the domain name.
    • setPassword

      public void setPassword(String password) throws MalformedURLException
      Throws:
      MalformedURLException
    • getPathname

      public String getPathname()
      Returns:
      a URLSearchParams object allowing access to the GET decoded query arguments contained in the URL.
    • setPathname

      public void setPathname(String path) throws MalformedURLException
      Throws:
      MalformedURLException
    • getPort

      public String getPort()
      Returns:
      the port number of the URL. If the URL does not contain an explicit port number, it will be set to ''
    • setPort

      public void setPort(String port) throws MalformedURLException
      Throws:
      MalformedURLException
    • getProtocol

      public String getProtocol()
      Returns:
      the protocol scheme of the URL, including the final ':'.
    • setProtocol

      public void setProtocol(String protocol) throws MalformedURLException
      Throws:
      MalformedURLException
    • getSearch

      public String getSearch()
      Returns:
      the query string containing a '?' followed by the parameters of the URL
    • setSearch

      public void setSearch(String search) throws MalformedURLException
      Throws:
      MalformedURLException
    • setSearch

      public void setSearch(List<NameValuePair> nameValuePairs) throws MalformedURLException
      Throws:
      MalformedURLException
    • getUsername

      public String getUsername()
      Returns:
      the username specified before the domain name.
    • setUsername

      public void setUsername(String username) throws MalformedURLException
      Throws:
      MalformedURLException
    • getDefaultValue

      public Object getDefaultValue(Class<?> hint)
      Calls for instance for implicit conversion to string.
      Specified by:
      getDefaultValue in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getDefaultValue in class HtmlUnitScriptable
      Parameters:
      hint - the type hint
      Returns:
      the default value
      See Also:
    • toJSON

      public String toJSON()
      Returns:
      a serialized version of the URL, although in practice it seems to have the same effect as URL.toString().
    • jsToString

      public String jsToString()
      Returns the text of the URL.
      Returns:
      the text