Internal Html js js file access to external variables

How to get inside the Html javascript external javascript files variables.

Window.XX to use.

See the following code:

<script type="text/javascript" src="index.js"></script>    
<script>
    var a=window.k;
    alert(a);
</script>

Code above is introduced into a first external js file index.js, then the value assigned through an external variable k js file is assigned to a, and then pop.

var a = window.k; 
below: index.js file has a parameter k

 

 

Then run html page, you can see the value of a pop-123456

 

 

carry out.

 

Guess you like

Origin www.cnblogs.com/masha2017/p/11462037.html