'How to load a script tag after loading all components in Blazor
In wwwroot/index.html (Blazor WebAssembly) or Pages/_Host.cshtml (Blazor Server) we can add a <script src="?"/> tag.
<body>
...
<script src="_framework/blazor.{webassembly|server}.js"></script>
<script src="?"></script> // I want to load this script after all components/site completely loaded.
</body>
But the problem is the <script src="?"/> tag just loaded but I want to load it after loading all components of Blazor. (Some functions inside the script cannot find some elements)
There is a way to load a JS function like below
@page "/"
@inject IJSRuntime JSRuntime
<div>
this is index page
</div>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("initilizeNiceAdminJs");// Initialize main.js after site completely loaded
}
}
}
The OnAfterRenderAsync method helps us to load a JS function after loading entire components in the Blazor.
Does exist any way to do the same with a <script src="?"/> tags instead of a function?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
