Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Inject javascript body in blazor wasm dynamically

All the methods I have seen in blazor wasm to inject Javascript involves calling a javascript function. what if I want to inject a dynamic javascript function block.
Example: await JS.InvokeVoidAsync("<script>alert('A')</script",null);
Is this possible? "InvokeAsync" only seems to accept a function name.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try it like this call the function name and then pass the data as an argument, as you’re directly invoking JS, the script tag is unnecessary

await JSRuntime.InvokeVoidAsync("alert", "Hello!");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading