Scott
Scott

Reputation: 33

How to include external javascript file without using the script tag

I am using a web app for my ecommerce store where they only allow you to add javascript via their input box. You are suppose to add javascript without any script tags.

However, I am trying to integrate a 3rd party analytics tools using the following code:

<script type="text/javascript" src="xxxx" async></script>

How can I add this to the input box without using script tags though? Are there alternative methods?

Thks

Upvotes: 1

Views: 2535

Answers (1)

Quentin
Quentin

Reputation: 943562

Write JS to modify the DOM to insert the script element.

(function () {
  const script = document.createElement("script");
  script.src = "xxx";
  script.async = true;
  document.head.appendChild(script);
})();

Upvotes: 6

Related Questions