Re: Javascript Question

by Nathan Lyle <natelyle(at)chartermi.net>

 Date:  Thu, 6 Dec 2001 21:41:52 -0500
 To:  Ben Ocean <lists(at)TheWebsons.com>
 Cc:  hwg-techniques(at)hwg.org
 References:  thewebsons
  todo: View Thread, Original
> I have a window that opens a child window via a Javascript. There is a link
> in said child that I would like to redirect the parent onUnload (and close 
> of said child). Unfortunately, parent.location doesn't work since that 
> simply references the child. What do?

Pass a reference of the parent to the child. Following is a snippet
from one of my efforts. Hope it helps. :)

In the head:

function showAnswer(self_reference) {
nw = window.open("","","");
if (!nw.opener) nw.opener = self;
  with (nw.document) {
    open();
    writeln("<html>");
    writeln("<body bgcolor=#ffffff>");
    writeln("<a href=\"javascript:this.close();\"onClick=\"" +
self_reference + ".location.href=\'http://www.url.com\';\">LINKTEXT</a>");
    }
  writeln("<a href=\"javascript:this.close();\">CLOSE</a></div>");
  writeln("</td></tr></table></div></form></body></html>");
  close();
  }
}

Somewhere in the body of the main window (this would open the child):

<a href="javascript:showAnswer(" + x + ",'opener.document');\"></a>

~Nathan Lyle   (The Tragic Comedian Poet)

Email: natelyle(at)chartermi.net
Phone: (906)485-4806
  Web: www.nathanlyle.com

"Tragedy is if I cut my finger, comedy is if I walk into an open sewer and die." - Mel Brooks

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA