Created
September 29, 2015 17:40
-
-
Save mightybyte/057876a285585c686566 to your computer and use it in GitHub Desktop.
Reflex Location Management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------------------------ | |
-- | Gets the current path of the DOM Window (i.e., the contents of the | |
-- address bar after the host, beginning with a "/"). | |
-- https://developer.mozilla.org/en-US/docs/Web/API/Location | |
getWindowLocationPathname :: DOMWindow -> IO String | |
#ifdef ghcjs_HOST_OS | |
getWindowLocationPathname w = do | |
jw <- toJSRef w | |
liftM fromJSString $ js_windowLocationPathname jw | |
foreign import javascript unsafe | |
"$1.location.pathname" | |
js_windowLocationPathname :: JSRef DOMWindow -> IO JSString | |
#else | |
getWindowLocationPathname = error "getWindowLocationPathname: only works in GHCJS" | |
#endif | |
------------------------------------------------------------------------------ | |
setWindowLocationHref :: String -> IO () | |
#ifdef ghcjs_HOST_OS | |
setWindowLocationHref = js_setWindowLocationHref . toJSString | |
foreign import javascript unsafe | |
"window.location.href=$1" | |
js_setWindowLocationHref :: JSString -> IO () | |
#else | |
setWindowLocationHref = error "setWindowLocationHref: only works in GHCJS" | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!