❔ 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
You can use the JSRuntime service
how exactly would that look like
Inject the IJSRuntiem into your component
cause ive used IJSRuntime but it seems that i failed to implement it
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?
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!
Sorry I was a little busy, good to hear it works!
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.