watermaniak
Embedded javascript inside of a liveview
I’m trying to embed some 3rd party javascript code inside of my LiveView page from Vesselfinder:
<script type="text/javascript">
// Map appearance
var width="100%"; // width in pixels or percentage
var height="300"; // height in pixels
var names=true; // always show ship names (defaults to false)
// Single ship tracking
var imo="9506291"; // display latest position (by IMO, overrides MMSI)
var show_track=true; // display track line (last 24 hours)
</script>
<script type="text/javascript" src="https://www.vesselfinder.com/aismap.js"></script>
If I just include this in my show.html.heex, this will not work as I have to refresh the page to make the embedded map visible (i.e., if I navigate directly to a page that should show the embedded map, it will show up but if I navigate from another LiveView to the page that’s supposed to show the embedded map, there is no map at all).
As Elixir is the first language I have learned, I have no experience with javascript, but I feel there should be something possible here with the Phoenix Liveview JS Hooks. Is there somebody that can point me in the right direction?
First Post!
tomkonidas
You can read over JS Interop and also check out this course from Pragmatic Studios if you learn better with video courses. This course touches on JS interop/integration
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










