aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes JS variable vs Scope variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JS variable vs Scope variable" Watch "JS variable vs Scope variable" New topic
Author

JS variable vs Scope variable

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I just came to know that Javascript variable are global, can be accessible from any file (JSP, HTML and Servlet).

Now I am thinking why we worry about scope and all, as soon as you get the data, store them into JS variable and then use them whenever you want...

Okay one drawback comes in mind is security, is that really a drawback???

Any other drawbacks???

Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
A JavaScript variable only lives on that page. It is not shared between pages unless you have parent/child(pop up windows or frames) references.

Not sure what you are talking about. You are making it sound like JavaScript can talk to the back end through variable scope.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

Originally posted by rathi ji:
I just came to know that Javascript variable are global, can be accessible from any file (JSP, HTML and Servlet).


Completely incorrect. Javascript variables don't even exist when the JSP and Servlets are executing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

I pointed you to this article in another post. You really need to read it.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Eric Pascarello:
A JavaScript variable only lives on that page. It is not shared between pages unless you have parent/child(pop up windows or frames) references.

Not sure what you are talking about. You are making it sound like JavaScript can talk to the back end through variable scope.

Eric


Actually, my project has lots of frame so I got this wrong impression.

Bear, thanks for the link, I will read it for sure as I get some time from the project.
 
 
subject: JS variable vs Scope variable