0

I have dynamic string javascript tags to execute in head of html.

Tags as follow and this tags is dynamic comes from server as a string and I want to execute this javascript into head of html. How can I best achieve this?

<script async src="/content/js/file1.js"></script>
<script async src="/content/js/file1.js"></script>
<script> alert('Execute'); </script>
2
  • What is the actual issue? Does the script tage arrive as a string? Why? Commented May 12, 2020 at 9:13
  • The actual issue is that, i create some external javascript file and i want to execute this script into the head of my project. Commented May 12, 2020 at 9:19

1 Answer 1

0

You have the right idea; the problem is that you can't combine an external script (using src) with an inline one.

You simply need two different scripts for this, making sure the inline one comes after the reference to an external script:

<script src=""></script>

<script type="text/javascript">
    document.getElementsByTagName("script")[0].src = "http://" + location.host + "/content/js/file1.js";
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.