admin管理员组

文章数量:1334886

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

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:

.0#javascript-isolation-in-javascript-modules

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./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./en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet?view=aspnetcore-6.0#javascript-isolation-in-javascript-modules

Share Improve this question asked Oct 22, 2022 at 17:49 JsonStathamJsonStatham 10.4k28 gold badges111 silver badges189 bronze badges 1
  • Does this answer your question? Blazor Server: load js scripts only on certain pages, not on all – Dimitris Maragkos Commented Oct 22, 2022 at 18:44
Add a ment  | 

2 Answers 2

Reset to default 3

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

Edited 2023-10-10

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

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

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

本文标签: javascriptHow do I add an external JS Script to a Blazor pageStack Overflow