Sharing variable within different javascript file at client side
Posted
by
Aman
on Stack Overflow
See other posts from Stack Overflow
or by Aman
Published on 2013-10-18T12:55:09Z
Indexed on
2013/10/20
21:54 UTC
Read the original article
Hit count: 233
JavaScript
|variables
I was actually going through this link. which explains how we can share global variable across multiple js. but the point is what need to be done if I am getting some variable into one js and need to pass to another one mentioned in same document after the 1st one.
approach which followed was:
Script 1 <script type="text/javascript" src="js/client.js"></script>
body added some hidden input with id myHiddenId, where values are set using client.js
Script 2 <script type="text/javascript" src="js/anotherJS.js"></script>
inside script 2 I am simply using $("#myHiddenId").val();
and using for my purpose.
I want to know whether I am following correct approach, because that hidden field may have some data which client should not get aware of. is there any other way through which I can pass the variable values across the js files ? Since I am at beginner level hence digging up some resources/books but still no luck.
© Stack Overflow or respective owner