In article <cg********@odah37.prod.google.com>,
"learner" <v_********@yahoo.com> wrote:
Hi,
In a page, i have many links.
I have some functions in a global file which is included in all
linked pages.
I want to have a reference to a window which is to be opened on
clicking one link and it should be known only to one more link on that
page and not to other links.
Are you using the HTML anchor tag <a> ?
In that case, Evertjan, The Netherlands, answered your question in the
prior post.
I cant have that window reference in that global file, since iam
declaring it initially as Null and modifying its value in that one
particular link. Since all links include this global file they change
the refernce to Null and its value is lost.
The web browser has the responsibility for security and that is a good
thing. The web browser controls the access to variables in a more
absolute manor than you see in c/c++.
How are you getting the window reference? The word link implies you are
using the anchor tag. The words window reference implies that you are
using the window.open function.
Lets say you had files a.html, b.html, and c.html all in the same
directory. Lets say you did this in file a.html:
var myData; // written outside of any function
window.open('b.html',...)
window.open('c.html',...)
Javascript functions in both b.html and c.html would be able to access
variable myData by coding:
opener.myData
You will note that functions in b.html and c.html do not have to declare
opener.myData.
Browser security will require files a.html, b.html, and c.html to all be
in the same directory unless you relax the default security settings.
What can i do for this?
I am not certain what your goal is. Are you trying to employ good
programming practices? Are you trying to encapsulate the data?
A web application can be very big. The nature of the web forces a
decentralized coding style. You will not see the monolithic programs you
find with c/c++ programs. In c/c++, you have to worry more about data
encapsulation. On the web, I think you will find the pieces are smaller.
The web forces you to write decentralized programs. You may feel more
comfortable using global variables in Javascript because there scope is
smaller in the overall picture of your application.
You can use closure to encapsulate your variables if you wish.
See:
http://jibbering.com/faq/faq_notes/closures.
I think you need to redesign your application.
Robert