I have two javascript files in one folder.I want to pass a variable one javascript file to another.what procedure should I use?
Asked
Active
Viewed 3,201 times
0
-
2Your title says 'one page to another', and your question says 'one javascript file to another'. They're very different concepts; which do you mean? – Delan Azabani Jul 18 '11 at 12:39
-
You are including both on the one page? Please add more detail, at the moment your question is unclear. – alex Jul 18 '11 at 12:39
-
exactly I want to send the variable one javascript file to another javascript file.they are in one folder. – lakshman Jul 18 '11 at 12:42
-
have a look at the below: http://stackoverflow.com/questions/1343801/pass-variable-to-external-js-file – Massimiliano Peluso Jul 18 '11 at 12:45
-
@lakashman And those JavaScript files are executed how? Are they included inside HTML pages which are loaded in a browser? – Šime Vidas Jul 18 '11 at 12:47
2 Answers
2
window.postMessage
is used for cross document messages. Use those messages to share data.

Raynos
- 166,823
- 56
- 351
- 396
0
Question is bit confusing, If the 2 javascript files are in 2 different pages you can use a query string to pass the values.
If both of them are in a single page the value can be simply passed using a variable. Simply define the variable int he first called script file or in the page. It can be accessed from any other javascript in the page defined below the first script.

Low Flying Pelican
- 5,974
- 1
- 32
- 43