Search code examples
javascripthtmliframecgiparent

javascript: reestablish parent for iframe


I have the following situation: A static web page, say whatever.html, which contains one iframe, both on the same website. The iframe contains a dynamic page (CGI/Perl), say cgi.pl?param=a; based on user action the content of the iframe will be replace by new pages (same CGI script with different parameters), say cgi.pl?param=b.

If the user opens only the iframe page I am able to redirect to the original parent page (the static HTML page):

if(self==top)
  top.location.href = "http://www..../whatever.html";

This works, but I would like that the iframe contained in that page is set to the dynamic page which reestablishes the parent. In my solution the iframe will contain only the default dynamic page (cgi.pl?param=a), but it should show cgi.pl?param=b in the iframe.

I hope I explained clearly.

Thanks for your help!

pi


Solution

  • The answer is straightforward. Use the script above to call the container web page with a parameter (e.g. test.html?abcd) and then use a script calling window.location.search.substring(1) to send the parameter to the iframe src.