Ask Your Question
2

What is the method to retrieve window.location.href in Elm?

asked 2021-11-06 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-01-13 16:00:00 +0000

lakamha gravatar image

In Elm, you can retrieve the window.location.href using the Browser.Navigation module. This module provides a function named getLocation which returns the current location of the page.

You can use the Browser.Navigation.getLocation function in your code as follows:

import Browser.Navigation

main =
  Browser.Navigation.getLocation (\location -> 
    -- Do something with the location variable here
    )

The getLocation function takes a callback function as an argument, which will be called with the location object. You can then use the location object to access the various parts of the URL, including the href property.

For example, you can retrieve the current URL's href property as follows:

import Browser.Navigation

main =
  Browser.Navigation.getLocation (\location -> 
    let href = location.href
    in
      -- Do something with the href variable here
    )
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-06 11:00:00 +0000

Seen: 10 times

Last updated: Jan 13 '22