Package org.htmlunit

Class History

  • All Implemented Interfaces:
    java.io.Serializable

    public class History
    extends java.lang.Object
    implements java.io.Serializable
    Representation of the navigation history of a single window.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      History​(WebWindow window)
      Creates a new navigation history for the specified window.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.htmlunit.History.HistoryEntry addPage​(Page page)
      Adds a new page to the navigation history.
      History back()
      Goes back one step in the navigation history, if possible.
      History forward()
      Goes forward one step in the navigation history, if possible.
      java.lang.Object getCurrentState()
      Returns current state object.
      int getIndex()
      Returns the current (zero-based) index within the navigation history.
      int getLength()
      Returns the length of the navigation history.
      java.net.URL getUrl​(int index)
      Returns the URL at the specified index in the navigation history, or null if the index is not valid.
      History go​(int relativeIndex)
      Goes forward or backwards in the navigation history, according to whether the specified relative index is positive or negative.
      void pushState​(java.lang.Object state, java.net.URL url)
      Allows to change history state and url if provided.
      void removeCurrent()
      Removes the current URL from the history.
      void replaceState​(java.lang.Object state, java.net.URL url)
      Allows to change history state and url if provided.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • History

        public History​(WebWindow window)
        Creates a new navigation history for the specified window.
        Parameters:
        window - the window which owns the new navigation history
    • Method Detail

      • getLength

        public int getLength()
        Returns the length of the navigation history.
        Returns:
        the length of the navigation history
      • getIndex

        public int getIndex()
        Returns the current (zero-based) index within the navigation history.
        Returns:
        the current (zero-based) index within the navigation history
      • getUrl

        public java.net.URL getUrl​(int index)
        Returns the URL at the specified index in the navigation history, or null if the index is not valid.
        Parameters:
        index - the index of the URL to be returned
        Returns:
        the URL at the specified index in the navigation history, or null if the index is not valid
      • back

        public History back()
                     throws java.io.IOException
        Goes back one step in the navigation history, if possible.
        Returns:
        this navigation history, after going back one step
        Throws:
        java.io.IOException - in case of error
      • forward

        public History forward()
                        throws java.io.IOException
        Goes forward one step in the navigation history, if possible.
        Returns:
        this navigation history, after going forward one step
        Throws:
        java.io.IOException - in case of error
      • go

        public History go​(int relativeIndex)
                   throws java.io.IOException
        Goes forward or backwards in the navigation history, according to whether the specified relative index is positive or negative. If the specified index is 0, this method reloads the current page.
        Parameters:
        relativeIndex - the index to move to, relative to the current index
        Returns:
        this navigation history, after going forwards or backwards the specified number of steps
        Throws:
        java.io.IOException - in case of error
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • removeCurrent

        public void removeCurrent()
        Removes the current URL from the history.
      • addPage

        protected org.htmlunit.History.HistoryEntry addPage​(Page page)
        Adds a new page to the navigation history.
        Parameters:
        page - the page to add to the navigation history
        Returns:
        the created history entry
      • replaceState

        public void replaceState​(java.lang.Object state,
                                 java.net.URL url)
        Allows to change history state and url if provided.
        Parameters:
        state - the new state to use
        url - the new url to use
      • pushState

        public void pushState​(java.lang.Object state,
                              java.net.URL url)
        Allows to change history state and url if provided.
        Parameters:
        state - the new state to use
        url - the new url to use
      • getCurrentState

        public java.lang.Object getCurrentState()
        Returns current state object.
        Returns:
        the current state object