I Have 3 html files & 3 js files
index.html,rank.html,score.html
global.js,rank.js,score.js
In index.html I have included rank.html and score.html using iframe.
In global.js I have declare Var rank; & global.js included in rank.html & score.html.
I am updating the value of rank in rank.js and i want to access the updated value in score.js. In score.js I dont get the Updated value It gives UNDEFINED value.
I dont want to include rank.js in score.html so i created global.js & included in html file.
Here is my code,
Index.html
<html>
<head>
</head>
<body>
<iframe src="../rank/rank.html" frameborder = "0" scrolling="no" width="50%" height = "100%"></iframe>
<iframe src="score.html" frameborder = "0" scrolling="no" width="50%" height = "100%"></iframe>
</body>
</html>
global.js
var rank;
score.js
$(document).ready(
function(){
setInterval(dataupdate, 10000);
});
function dataupdate() {
alert(rank)
};
rank.js
$(document).ready(
function(){
setInterval(dataupdate, 10000);
});
function dataupdate() {
rank = "first";
};
I want updated value of rank in score.js file how to access that value…
Thanks…..
When you declare a global variable like you’ve done it gets created as a property of the
windowobject, i.ewindow.rank. Your main window and the 2 iframes have separatewindowobjects and thereforewindow.rankassigned from the main frame is not the samewindow.rankaccessed from one of the iframes.For accessing the rank property of the main window object from inside an iframe, you can use
parent.rankinstead ofwindow.rank