how to run a html file from js code example

Example 1: how to open html file with javascript

// In my case, I used a button to activate this function:
function myFunction() {
    window.location.href = 'index.html';
}

Example 2: html execute javascript

<!-- 
	Method 1: external script 
	- Should be placed in the <head> section of your HTML
	- The 'src' should contain the path to a local file or external URL
	- The 'defer' attribute will make it execute after the DOM is loaded
-->
<script src="script.js" type="text/javascript"></script>
<script src="script.js" type="text/javascript" defer></script>

<!-- 
	Method 2: inline code 
	- Should be placed in the <head> or <body> section of your HTML
 	- Place it before the </body> to make it execute after the DOM is loaded
-->
<script> alert("Hello world!"); </script>