[elm-discuss] Re: How do I open a URL?

2017-01-17 Thread Tomáš Znamenáček
Thank you very much, the port approach worked well for me.

T.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How do I open a URL?

2017-01-06 Thread Wouter In t Velt
Over on SO I just posted an answer (see below) to the question there.
Your case is different, because you do not have want to navigate away based 
on a click, but from your update function.

In your case, I would suggest to use a port:

   - Send the url as a string through a port to javascript
   - In javascript, call `window.location.href = urlFromElm`


-
To make any item a clickable link (similar to providing a href to an a 
element) there is hack that you could use:  
Supply a one-liner of javascript to an Elm style attribute. Using 
`attribute` from the `Html.Attributes` library.

You could make your own helper that does the redirect:

redirectTo : String -> Attribute msg
redirectTo destinationUrl =
  attribute 
"onclick" 
("window.location.href = ' ++ destinationURL ++ "'")


Which you can add to any element like this:

button 
  [ class "mdl-button", redirectTo "https://google.com"; ]
  [ text "Click to leave" ]

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: How do I open a URL?

2017-01-06 Thread Wouter In t Velt
There is this somewhat dirty hack you could use:  
Supply a one-liner of javascript to an Elm style attribute. Using 
`attribute` from the `Html.Attributes` library.

You could make your own helper that does the redirect:

redirectTo : String -> Attribute msg
redirectTo destinationUrl =
  attribute 
"onclick" 
("window.location.href = ' ++ destinationURL ++ "'")


Which you can add to any element like this:

button 
  [ class "mdl-button", redirectTo "https://google.com"; ]
  [ text "Click to leave" ]

I posted the same answer just now over on SO.


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.