Passing variables between frames

Results 1 to 2 of 2

Thread: Passing variables between frames

  1. #1
    Join Date
    Dec 1969

    Default Passing variables between frames

    I am trying to pass some variables between two frames on a page.<BR><BR>Frame 1, name = "Reference"<BR><BR>&#060;script language=Javascript&#062;<BR> <BR>Test = "Hello"<BR><BR>&#060;/script&#062;<BR><BR><BR><BR>Frame 2, name = "Main"<BR><BR>&#060;body&#062;<BR><BR>&#060;sc ript language=Javascript&#062;<BR><BR>document.write(pa rent.Reference.Test)<BR><BR>&#060;/script&#062;<BR><BR><BR>When I load the page I sometimes get "Test" but sometimes I get "undefined". It appears to be random every time I press refresh.<BR><BR>Any Ideas<BR><BR>Cheers Mike

  2. #2
    Join Date
    Dec 1969

    Default RE: Passing variables between frames

    I think that this is because Frame1 has not finished loading when Frame2 tries to refer to it<BR><BR>try this in Frame1 page<BR>&#060;body onLoad="parent.Main.location.href=&#039Frame2.htm& #039"&#062;<BR><BR>then in Frame2 script would be<BR>if parent.Reference.Test != null { document.write(parent.Reference.Test); }<BR><BR>only thing is Frame2 will then load twice, but unless you are in control of the order in which the pages load from JavaScript using location.href for example I don&#039t think there is much option<BR><BR>hope that helps!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts