Link javascript in two html files

0

I'm starting to see javascript and I have two html pages with javascript content. In one I have a method and in another I have to show the result of that function. I tried calling it in the header and just before calling the method, but it does not work for me. These are the two pages: js.html:

<html><head><title>js</title></head><body>
<script src="C:\Users\cdum7\Desktop\js\js1.html">
document.write(miFuncion(4,5));
</script>
</body></html>

js1.html:

<html><head></head><body>
<script>
function miFuncion(a,b){
    c=a+b;
    return c;
}
</script>
</body></html>
    
asked by Charly Utrilla 16.02.2018 в 16:58
source

2 answers

1

Create a file called functions.js and hit

function miFuncion(a,b){
c=a+b;
return c;
}

then the call would be the following

    <script src="funciones.js"></script>
   <script>

            document.write(miFuncion(4,5));

   </script>
    
answered by 16.02.2018 / 17:32
source
1

I recommend that you improve the structure of your project, you can take a base of this.

Having your project well structured, you could refer to your js file in this way: <script src="js/main.js"></script>

Your JavaScript files should always have a .js extension and to send your function within your Html document it would be enough to call the function in the following way:

<script>
    myFunction(4, 5);
</script>

I hope it's your help.

    
answered by 16.02.2018 в 17:19