❔ Use Javascript in Blazor Server App

Hey, I just started developing Web Apps using Blazor but im current facing an issue I have a Javascript file that controls my navigation bar (mobile responsiveness, animations etc) and I'd like to invoke it when the page loads (I've put it into the navbar in MainLayout.razor) but apparently it seems like the <script> tag won't work cause it "cant update dynamically", it's important that the whole JS file loads and not just the functions, because otherwise it would break some stuff Big thanks in advance
9 Replies
artya
artya2y ago
You can use the JSRuntime service
The Fog from Human Resources
how exactly would that look like
artya
artya2y ago
Inject the IJSRuntiem into your component
The Fog from Human Resources
cause ive used IJSRuntime but it seems that i failed to implement it
artya
artya2y ago
Since you want to load the JS file I think you could call invoke in the OnAfterRenderAsync method So you'd override the OnAfterRenderAsync method in your component Perhaps you'd have a function in your JS file that dynamically creates a script tag and appends it to the body element?
The Fog from Human Resources
is there a specific way i need to override OnAfterRenderAsync it seems to work now i used OnAfterRenderAsync to get the script to load tysm!
artya
artya2y ago
Sorry I was a little busy, good to hear it works!
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server