How to access a variable declared in one javascript in another javascript ?

Please help me with the code.

Thanks in advance.

Recommended Answers

Are the two javascripts in the same web page?

Jump to Post

All 4 Replies

Are the two javascripts in the same web page?

the two scripts are in different pages... any solution ???

Are both pages in the same domain? browsers block cross domain scripting by default.

You could pass a variable on the query string.

In your first html it would look something like this.

<a href="#" id="mylink" title="Home">Click Me</a>
<script>
    var myvar = "test";
	document.getElementById("mylink").href="www.google.com?" + myvar;
</script>

And your receiving html would look something like this.

<script>
var loc = location.href;
loc = loc.toString();
var arr = loc.split("?");
var myvar = arr[1];
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.