开发者

Add external URL using script tag in React js app

开发者 https://www.devze.com 2022-12-07 18:02 出处:网络
My requirement is to add the external website vi开发者_StackOverflow社区a script tag to my react js project.

My requirement is to add the external website vi开发者_StackOverflow社区a script tag to my react js project. I have already tried react-helmet and react-script-tag.

I have added using it custom function while inspecting the UI, I am able to view the script added into the head but still UI is not rendering.

This is my App.js

import React from 'react';
import './App.css';
  
export function AddLibrary(urlOfTheLibrary) {
  const script = document.createElement('script');
  script.src = urlOfTheLibrary;
  script.async = true;
  document.head.appendChild(script);
}
  
function App() {
  return (
    <div className="App">
  {AddLibrary(
  'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js')}
    </div>
  );
}
  
export default App;

It would be really great to get some help here.

Thanks in Advance.


If I got it right, you want to add a script tag so it is working immediately, for security reasons the browser will not allow run it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号