user7279967
user7279967

Reputation: 1

How to dynamic load html file and execute the exernal js in it

I have an html file:index.html which contains some basic js libs. And I also have some modules:

a.html:

<div id='a'>
  <script src="a1.js"></script>
  <script src="a2.js"></script>
</div>

a1.js:

console.log('a1')

a2.js:

console.log('a2')

How can I dynamically load a.html into index.html and get the event that a1.js and a2.js are completed executed?

Upvotes: 0

Views: 934

Answers (1)

Md. Nasir Uddin Bhuiyan
Md. Nasir Uddin Bhuiyan

Reputation: 1596

use w3data.js to do that ( w3data.js )

Example: in index.html

<html>
<script src="http://www.w3schools.com/lib/w3data.js"></script>

<body>

<div w3-include-html="a.html"></div> 

<script>
w3IncludeHTML();
</script>

</body>
</html>

Upvotes: 1

Related Questions