By declaring "var module" inside the function, that variable only exists
inside the function. If you need access to that variable outside the
function, you need to either return it from the function (i.e. return
module; ) or declare the variable in the global scope. Something like this:
<script>
var module = null;
$(function () {
module = { . . . }; // reset the global variable to some value
});
</script>
Now you can refer to that module variable from inside your iframe with
console.log( window.parent.module );
(Assuming I am remembering my terms right - it's been a long while since
I needed to do this...) In that statement, "window" refers to the
current window - aka the frame. "parent" refers to the element that
contains the window if one exists (refers to itself if it IS the top).
Global variables (and functions) are properties of the window - not the
document.
Then only part I'm not sure on is the use of the $() function in your
code. I'm not sure if jQuery places the defined function on the global
stack or not. If so, then you shouldn't even need the first part....
Hope that helps.
Shawn
jay wrote:
perhaps you need to do this.module = {...}? Doing var module makes it
"private" I believe
On Jan 23, 3:31 pm, jquertil <til...@gmail.com> wrote:
I'm using frames (don't ask) and have exhausted my abilities
(sniff)... here is some pseudo-code to illustrate the situation:
------------------------ first, CONTAINER.HTM:
<script src=jquery.js></script>
$(function(){
var module = {
something1 : function(var1){
alert(var2);
}
}
});
<iframe src=iframe1.htm></iframe>
------------------------- now, IFRAME1.HTM
<script src=jquery.js></script>
$(function(){
$('#myDiv').click(function(){
top.frames[0].document.module.something1('hello');
// this line above is the part where I'm stuck.
//why won't this darn thing cooperate and alert my variable?
});
});
<div id=mydiv>click me</div>