I think this is a simple question. Imagine you have a page that initializes a JS variable named channel
:
<html>
<script>
$(document).ready(function() {
...
var channel = new Channel();
channel.send("helo");
}
</script>
<body>
<div id="placeholder"></content>
</body>
</html>
The page also contains a div with id="placeholder" which content is loaded using AJAX. That external content have to access the channel
variable.
Is there any good practice or advice about where to store the variable? The following code works but I do not like it:
<html>
<script>
var channel;
$(document).ready(function() {
...
channel = new Channel();
channel.send("helo");
}
</script>
...
</html>
Thank you.