Next, how can I do to pass data between two files with javascript? Example:
File1:
<script>
var dado = 'dado';
</script>
File2:
<script>
alert (dado);
</script>
Next, how can I do to pass data between two files with javascript? Example:
File1:
<script>
var dado = 'dado';
</script>
File2:
<script>
alert (dado);
</script>
You have to consider 2 things:
alert();
. In other words, this code loaded first. If they are not in the same scope you can use a global object for this variable to be accessible:
File1:
<script>
window.dado = 'dado';
</script>
File2:
<script>
alert(window.dado);
</script>
If you are using different HTML pages, you can use the % a> and use localstorage
instead of the example with localstorage
I gave above.
Example where you write to the localstorage: link
Example where it reads from the localstorage: link