JsonStatham
JsonStatham

Reputation: 10374

How do I add an external JS Script to a Blazor page

I'm trying to integrate Stripe payments to my Blazor application. Straight away as predicted I must have a <script> tag on my page.

https://stripe.com/docs/billing/quickstart

My question is, how do I add this script tag to a Razor page in Blazor. I've used interop to define my own JS files and call their methods, but i need this script to just be added to the DOM.

This documentation only shows me how to connect to my own JavsScript files:

https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet?view=aspnetcore-6.0#javascript-isolation-in-javascript-modules

Upvotes: 8

Views: 9016

Answers (2)

VERC.ONLINE
VERC.ONLINE

Reputation: 1

Continuing answer of Sajjad Arash At the bottom of the page add:

<script src="../Components/Pages/Component.razor.js"></script>

Upvotes: 0

Sajjad Arash
Sajjad Arash

Reputation: 349

you can use new feature of blazor wasm and Use JSExportAttribute and JSImportAttribute and Handle your js modules in .net also you can read documentation here

Edited 2023-10-10

in .NET 8 you can add external JS files in your razor components and pages with <script> tag and compiler no longer given error to using that

Upvotes: 3

Related Questions