CGI that opens new, small top window

Posted on 2004-09-10
Last Modified: 2013-12-25
This may not be the right area to ask this question, if not, point me to the right one.

Our site has a huge archive of past issues of a daily web page (20 times a month)...1998-2004. I want to scrap the static index.html pages to the pages  and instead dynamically build the index to the past issues with two small options pulldowns for the user: Year and Month , which then are passed to a CGI... the CGI checks the directories for that year/month and builds a small set of links for the days when the page was posted, poke these into a small html template file and then send back to the client a small list of all the issues on line in the archives for that month. Actually, that is all a piece of cake... Easy enough...

but is it possible for the CGI to tell  the browser to open a new top window with a smaller rect? instead of simply taking over the current window? I want the index page to the past issues to in a small window in top of the window they were viewing. If they dismiss the index... they drop back to the window they were in.  the browser window from which the CGI call was POSTed, remains there, in the back, unchanged.  Of course I know about  java popupwindow functions, and for links "target="_blank"  but what I think i need is some preloading directive that would be in the http header, so that the browser know, hey open a new top window with this rect...  is that possible?


<links deleted by COBOLdinosaur>
Question by:Sivakatirswami
  • 4
  • 4

Expert Comment

ID: 12034785
I don't think that the CGI could open a new window directly BUT you could open it with Javascript and pass the url as blah.cgi?month=12&year=2003 which would allow the CGI script to return it's value into the new window. If the field is blank it could return <script>window.close;</script> or something similar.
LVL 53

Expert Comment

ID: 12036277
Yoiu might want to use an iframe instead.  They can be hidden and re-sized dynamically, and all that would be required on the main page is the tag:
<iframe name="XX" height="1" width="1" src=""></iframe>
Then you can use target="XX" in the form or in links for any thing you want load there.

The height and width of 1 evvective make it invisible until needed and all you have to do to bring it up is when you generate the body tag of the links page do this:
<body onload="resizeTo(400,200)">

Or yo can do it in script form the main page with:


Author Comment

ID: 12036805

Fascinating... I never knew about iFrames.   so I may need a little more to fill in the  gaps for implementation.

 I have the option pull downs  in a little form Year Month, submit POST action to buildIndex.cgi in a side bar column in between other links above and below.  just underneath the submit button i would insert

<iframe name="XX" height="1" width="1" src="">##I presume the html chunk would go here?## </iframe>

as you have suggested.

How do  I get the html chunk which I presume it is a complete html doc, since it has the body onload="resizeTo(400,200)">
?)  to use target ="XX"

Thank you!

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

LVL 53

Expert Comment

ID: 12036921
You just do the iframe this way:
<iframe name="XX" height="1" width="1" src=""></iframe>
The content HTML gets generated by buildindex.cgi as the response page.

The form tage would look like this:
<form method="post" action="buildindex.cgi" target="XX">

That tells the browser to load the response back from the script into the iframe.

It means minimum coding on the page to implement.  I assume that buildindex.cgi is already returning a response page so you just have to change the generation of the body tag to set the sizing.



Author Comment

ID: 12036948
Sorry about the links... I didn't realize that... no problem, won't do it again..

OK... your guidance is clear... Thanks

Yes the CGI does return the response page...  Let me play with this and then get back to you in a day or so..

I look up iFrames in and the warning about older browsers not seeing anything ....  is there a compatibility chart for iFrames somewhere on the net?

LVL 53

Expert Comment

ID: 12036977
The older browsers referred to are Netscrap 4 and earlier.  If you look at yur server logs you will probably find that your users do not use anything that old.  if you do ahve to support back that far, you are proabaly going to run into issues with Netscrap 4 no matter what approach you take.


Author Comment

ID: 12040767
Aloha, CobolD:

I implemented your  proposal as best I could .... but

<iframe name="archiveIndex" height="1" width="1" src=""></iframe>

<form method="post" action="buildindex.cgi" target="archiveIndex">

with the opening of the response from the cgi as:

<body onload="resizeTo(400,200)"> ## list of links here </body>  ## which is returned by the cgi

causes the entire top-main window to resize... and the embedded iFrame does not expand at all (firefox 9 on mac, latest safari on mac)

If I do this:

<iframe name="archiveIndex" height="120" width="140" src=""></iframe>

<form method="post" action="buildindex.cgi" target="archiveIndex">

The same thing happens: main window resizes to 400, 200, but, when I drag open the window, I now see the response links (in a right  floading side div)  for the month *are* now appearing in the iFrame -- because I hard coded enough dimensional space for them to appear.   So, the CGI is working.

But, how to  instruct the iFrame to dynamically resize to accept the content coming from the cgi, while leaving the rect of the main window in which it is embeded, unchanged?

but this was a *very* useful exercise... I never knew about iFrames... very powerful tool.. as a temp work around I set fixed dimension for the iFrame,  and in order not to have a blank area, set src to the cgi, which responds differently if the request is a GET which it is on page load... and it puts in the current month by parsing today's date: html and cgi code below... but the above question remains.

###### HTML #####

<li> Archives: <br />
## iFrame with hard coded dimenion to hold content from cgi stdout
## height ="1" and width="1" will not work

<iframe name="archiveIndex" border="0" width="130" height ="140" src="/cgi-bin/buildTakaIndex.cgi"></iframe></li></ul>
## user can navigate the past with:
<form method="post" action="/cgi-bin/buildTakaIndex.cgi" target="archiveIndex">
<select name="month"> ## option list here for 12 months.##</select><br>
<select name="year">##option list for years in the archive## </select>
<input type=submit value="Go"></form>

###### CGI  #####
### uses the Revolution transcript interpreter ###

on startup
global tYear, tMonth


## user has made selections from the option pull downs and submitted      
## trap the data

put "" into PostIn
      repeat until length(PostIn) >= $CONTENT_LENGTH
            read from stdin until ""
                put it after PostIn
        end repeat        
      put  urlDecode (PostIn)  into tDataIn       
# create small array:

split tDataIn by "&" and "="

#extract elements

put tDataIn["year"] into tYear
put tDataIn["month"] into tMonth

## this is a GET request from the page on first load
## just  parse today's date:
## and insert the current month's links

put word 1 of item 2 of the long date into tMonth
put item 3 of the long date into tYear

#we have to wipe leading space
delete char 1 of tYear

end if

#  create a path now to the past
# and get directory list of days for the month

put "../taka/past/" & tYear& "/" &tMonth &"/" into tArchiveMonth
 set the defaultFolder to tArchiveMonth
 put the folders into tMonthList
 # We have our list of days now just have to
#  build html response
 ##put format ("<body onload=\"resizeTo(200,200)\"") into tIndex
 ## this "onload" directive re-sizes the main window
 ## meanwhile the iFrame remains at 1 pixel in width
## and output from this CGI is not visible
 ## so I took it out and put simply:
put "<body> into tIndex
 put "<h4>" & tMonth & ", " & tYear & "</h4>" after tIndex
## create the links chunk

repeat for each line x in tMonthList
  if x contains tMonth then #skips dot files
  put tagIt(x,tYear,tMonth) & "&nbsp;" after tIndex
  end if
end repeat
put "</body>" after tIndex

## We're done, just send it to stdout,  minimal http headers first:

put "Content-Type: text/html" & cr
put "Content-Length:" && the length of tIndex & cr & cr
put tIndex

end startUp

function tagIt tDay,tYear,tMonth
  set the itemdel to "_"
  put format (cr & "<a href=\"/taka/past/")& tYear & "/" &tMonth &"/" & tDay & format ("/\" & target=\"_blank\">") & item 2 of tDay & "</a>" into tDayLink
  return tDayLink
end tagit


LVL 53

Accepted Solution

COBOLdinosaur earned 500 total points
ID: 12045938
It looks like the sizing has to be dynamic in the mainpage as the form is submittted; and we probably have to use the styles to do it.

We can use the onsubmit event of the form to trigger:
<form method="post" action="buildindex.cgi" target="archiveIndex"

A small script goes in the head of the main page

<script type="text/javascript">
function setSize()

And we us the sam value for both the id and the name of the iframe:

<iframe id="arhchiveIndex" name="archiveIndex"
    style="height:1px;width:1px" src=""></iframe>


Author Comment

ID: 12214593
I'm sorry I didn't get back to you sooner... very busy here ... I finally opted for a fixed iFrame size set on the html page itself... While our solution was not that of the original question...,  it turned out to be much better web design anyway.. We are not popping open anything.. the iFrame is static, sized to fit in the side bar and comfortably hold the data we want to display...

You open a lot of new doors for me... thank you! ;-)


Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question