Options
All
  • Public
  • Public/Protected
  • All
Menu

An abstraction of the browser entity an all its related operations and properties Browser entity is normally available only on client side or front end view applications, but some of its features can also make sense on a server side app. So depending on the implementation language, this class may or may not have some of its methods implemented.

Hierarchy

  • BrowserManager

Index

Methods

Private _onPopStatePreventBackButton

  • _onPopStatePreventBackButton(): void
  • Event listener that will prevent the back button when disableBackButton is enabled

    Returns void

browseLocalFiles

  • browseLocalFiles(event: any, mode: "TEXT" | "BASE64", callback: (fileNames: string[], fileContents: string[]) => void): void
  • Search for a file or files on the local user machine. Their contents will be loaded into the browser memory and can be used locally without needing to update them to a remote server.

    Parameters

    • event: any

      It is mandayory for security reasons that an event from an actual input type='file' element is passed to this method. We can set here for example the change event that is fired by the input when the user selects a file.

      Example for single file: <input type='file' accept=".txt" (change)="onFileSelected($event)"> (call browseLocalFiles() inside the change event handler)

      Example for multi files: <input type='file' multiple="multiple" accept=".txt" (change)="onFileSelected($event)"> of the onFileSelected method.

    • mode: "TEXT" | "BASE64"

      Specify if the files must be loaded as plain "TEXT" or "BASE64" encoded binary data

    • callback: (fileNames: string[], fileContents: string[]) => void

      Once the files selected by the user are correctly loaded into the browser, this callback method will be called with two parameters containing the name and contents for each one of the loaded files.

        • (fileNames: string[], fileContents: string[]): void
        • Parameters

          • fileNames: string[]
          • fileContents: string[]

          Returns void

    Returns void

    Void. (An exception will be thrown if the load fails)

copyToClipboard

  • copyToClipboard(text: string): Promise<void>
  • Copies the specified text to the clipboard

    Parameters

    • text: string

      Some string that will be placed on the system clipboard

    Returns Promise<void>

    Promise A promise to be resolved once the copy is performed

deleteCookie

  • deleteCookie(key: string, path?: string): boolean
  • Deletes the specified cookie from browser. Note that the cookie will only be deleted if belongs to the same path as specified.

    Parameters

    • key: string

      The name of the cookie we want to delete

    • Default value path: string = "/"

      Define the path where the cookie is set. By default it is the whole domain: '/'. If the cookie is not set on this path, we must pass the right one or the delete will fail.

    Returns boolean

    True if cookie was deleted or false if cookie could not be deleted or was not found.

deleteCurrentUrlHashFragment

  • deleteCurrentUrlHashFragment(): void
  • TODO

    Returns void

disableBackButton

  • disableBackButton(): void
  • Disable the hability for the user to navigate back on browser history. This method does not disable the browser back button, but it prevents it from leaving the current page.

    Returns void

    void

disableScroll

  • disableScroll(): void
  • Totally disables the current page scrolling. Useful when creating popups or elements that have an internal scroll, and we don't want it to interfere with the main document scroll.

    Can be enabled again with enableScroll.

    Returns void

    void

enableBackButton

  • enableBackButton(): void
  • Restore the back button normal behaviour which was blocked by calling disableBackButton()

    Returns void

    void

enableScroll

  • enableScroll(): void
  • Restores main document scrolling if has been disabled with HtmlUtils.disableScroll

    Returns void

    void

getCookie

  • getCookie(key: string): string
  • Get the value for an existing cookie.

    Adapted from the jquery.cookie plugin by Klaus Hartl: https://github.com/carhartl/jquery-cookie

    Parameters

    • key: string

      the name of the cookie we want to get

    Returns string

    Cookie value or null if cookie does not exist

getCurrentUrl

  • getCurrentUrl(): string
  • Get the current page full url, including 'https://', domain and any uri get parameters

    Returns string

    A well formed url

getCurrentUrlHashFragment

  • getCurrentUrlHashFragment(): string
  • Obtain the value that is found at the current URL hash fragment part. For example: https://someurl.com/home#somehash

    Will return 'somehash'

    Returns string

    The value of the URL hash fragment but without the # character

getCurrentUrlQueryValues

  • getCurrentUrlQueryValues(): void
  • TODO

    Returns void

getDocumentHeight

  • getDocumentHeight(): number
  • Obtain the current html document height in pixels

    Returns number

    Numeric value representing the document height in pixels

getDocumentWidth

  • getDocumentWidth(): number
  • Obtain the current html document width in pixels

    Returns number

    Numeric value representing the document width in pixels

getPreferredLanguage

  • getPreferredLanguage(): any
  • Tries to detect the language that is set as preferred by the user on the current browser. NOTE: Getting browser language is not accurate. It is always better to use server side language detection

    Returns any

    A two digits string containing the detected browser language. For example 'es', 'en', ...

getScrollPosition

  • getScrollPosition(): number[]
  • Gives the current position for the browser scroll

    Returns number[]

    Array with the current x,y position based on the top left corner of the current document

getWindowHeight

  • getWindowHeight(): number

getWindowWidth

  • getWindowWidth(): number

goToUrl

  • goToUrl(url: string, newWindow?: boolean, postData?: Object | null): void
  • Opens the specified url on the browser's current tab or in a new one.

    Parameters

    • url: string

      The url that will be loaded

    • Default value newWindow: boolean = false

      Setting it to true will open the url on a new browser tab. False by default

    • Default value postData: Object | null = null

      If we want to send POST data to the url, we can set this parameter to an object where each property will be translated to a POST variable name, and each property value to the POST variable value

    Returns void

    void

isCookie

  • isCookie(key: string): boolean
  • Check if the specified cookie exists

    Parameters

    • key: string

      the name for the cookie we want to find

    Returns boolean

    True if cookie with specified name exists, false otherwise

isCurrentUrlWithHashFragment

  • isCurrentUrlWithHashFragment(): boolean
  • Check if the currently active URL at the browser contains a hash fragment. The fragment is a part of the URL that comes after the # symbol, and can be modified without needing to reload the page. It is important to know that the url fragment is always available at the browser level and will never be sent to server.

    An example of a hash: https://someurl.com/home#somehash

    Returns boolean

    True if the active URL has a hash fragment, false otherwise.

isCurrentUrlWithQuery

  • isCurrentUrlWithQuery(): void
  • TODO

    Returns void

isDocumentLoaded

  • isDocumentLoaded(): boolean
  • Tells if the current html document is fully loaded or not.

    Returns boolean

    True if the current html document is fully loaded (including all frames, objects and images) or false otherwise.

reload

  • reload(): void
  • Reloads the current url. This will make the browser load all the current html document again and all page state will be lost.

    Returns void

    void

scrollTo

  • scrollTo(destination: HTMLElement | [number, number], duration?: number, callback?: Function | null): void
  • Moves the browser scroll to the specified X,Y axis position or DOM element.

    example

    browserManager.scrollTo(document.querySelector('#myId'), 800);

    example

    browserManager.scrollTo([100,200], 1000);

    see

    https://pawelgrzybek.com/page-scroll-in-vanilla-javascript/

    Parameters

    • destination: HTMLElement | [number, number]

      The location where the scroll must be moved to. It can be an HTML element instance or an array of two numbers with the [x,y] destination coordinates

    • Default value duration: number = 600

      The animation duration in miliseconds. Set it to 0 to perform a direct scroll change.

    • Default value callback: Function | null = null

      A method that will be executed right after the scroll finishes

    Returns void

    void

setCookie

  • setCookie(key: string, value: string, expires?: any, path?: string, domain?: string, secure?: boolean): boolean
  • Set the value for a cookie or create it if not exist

    Adapted from the jquery.cookie plugin by Klaus Hartl: https://github.com/carhartl/jquery-cookie

    Parameters

    • key: string

      the name for the cookie we want to create

    • value: string

      the value we want to set to the new cookie.

    • Default value expires: any = ""

      The lifetime of the cookie. Value can be a Number which will be interpreted as days from time of creation or a Date object. If omitted or '' string, the cookie becomes a session cookie.

    • Default value path: string = "/"

      Define the path where the cookie is valid. By default it is the whole domain: '/'. A specific path can be passed (/ca/Home/) or a '' string to set it as the current site http path.

    • Default value domain: string = ""

      Define the domain where the cookie is valid. Default: domain of page where the cookie was created.

    • Default value secure: boolean = false

      If true, the cookie transmission requires a secure protocol (https). Default: false.

    Returns boolean

    True if cookie was created, false otherwise. An exception may be thrown if invalid parameters are specified

setCurrentUrlHashFragment

  • setCurrentUrlHashFragment(): void
  • TODO

    Returns void

Generated using TypeDoc