Reputation: 1945
I am building a very basic game entirely in JavaScript and jQuery. It consists of two pages. The first page, lists all the rules and other stuff. The second one actually consists of the game. I want to implement Facebook login and make API calls on the first page. I want to get the Name and profile picture of the user and use it in the second page.
However, I strictly want to keep the javaScript files of both the pages seperate. I don't want to pollute the JavaScript of my main game. So my question is, Is there any way of "storing" content in variables in javascript file of first page and retrieving and using it in the javaScript file of second page?
Upvotes: 1
Views: 51
Reputation: 507
Is following that you are looking for:
In first.js
, you define
var firstName="tom";
In second.js
, you can use that firstName
function returnFirstName(){
return firstName; //use variable defined in first.js
}
But you need connect those two file in Index.html
<script src="./first.js" />
<script src="./second.js" />
<script>
returnFirstName(); //call function defined in second.js
</script>
Upvotes: 1