-2

i have this javascript script shared between all my web pages:

if(document.location.pathname == '/' || document.location.pathname == '/index.php'){
window.hello='hello';
window.alert(window.hello);
}
else
{
window.alert(window.hello);
}

the window.hello variable should be (as far as i know) a cross page variable, so it should display 'hello' in every page (having first loaded index.php), but that happens only in the index page, while the others display 'undefined' .... someone knows why?

1 Answers1

-1

window.hello is a global variable and is added as a property to the global object.

A new global object is created for each page, hence your problem...

Ben Aston
  • 53,718
  • 65
  • 205
  • 331