View Full Version : Generating Pop-up Window

01-19-2006, 04:45 AM
First off, as usual, I would like to thank all you kind folks that have helped me in the past. My most recent project (Stellar Body Position Calculator) has turned into a "Stellar" success. :p Now, however, I am looking to add some new features.

One of the features I would like to add is to allow the user to generate results for several Stellar Bodies. This, in and of itself, is not going to be a huge problem. What is going to be a problem, however, is displaying those results. My thought is to provide a "calculate" button that not only generates the results, but also stores them in an array. Again, not too much of a problem. What I would like to do with that array is render it in Table Format in a pop-up window so that the user can either print or save it in some fashion.

What I have accomplished so far is;

-Generating the array of values
-Opening the pop-up window

What I need now is a way to pass the information in the array to the pop-up window. I'm not sure if this is even possible using Javascript, but if it is, could one of you fine folks point me towards a tutorial that might help me figure out how to do this since I don't want to burden any of you with writing code that I need to learn how to write for myself?


01-19-2006, 06:26 AM


from the new window.

01-19-2006, 02:39 PM
Thanks for the suggestion, fishluvr, but what I am really looking for is a tutorial on the subject rather than a quick answer. Since I am still in the midst of the learning curve when it comes to JScript, I am trying to understand what it is I am doing rather than simply cutting and pasting the stuff other people have done. I seem to remember a tutorial about this subject being located at Javascriptkit.com, but cant seem to find it now so I was hoping someone here might know where I could find one.


01-23-2006, 12:55 PM
main page:

function doOpen(){
var w = window.open("", "popup", "width=600, height=400, resizable=1"); //create a blank window
//generate html tags
var html = '<html><head><title>Popup</title></head><body>\n';
html += '<table>';

//loop through the array to store the content in "html" variable

html += '</table></body></html>';
w.document.write(html); //output html tags to popup window
w.document.close(); //close the output stream
w.focus(); //set focus to the popup window

01-23-2006, 06:19 PM
Once again I find myself thanking you Glenn. I did manage to find a tutorial on the subject, but it wasn't very clear. Coupled with your code, however, it now makes sense.



01-23-2006, 10:29 PM
Actually, anyone can answer, but I figured I would direct this towards Glenn first since he was the one that supplied the coding base for what I am trying to accomplish.

The scripting you laid out looks at though it will work just fine for what I am trying to accomplish, however, I was wondering if . .

1: I can add a doctype to the html variable
2: I can add CSS, Javascript and/or Meta info to the "head" portion of the html variable.

From what I can see, I don't think it would cause a problem if I added these things in (mostly the doctype and CSS) but if there is a problem with adding those things, I figured I better ask before I pull my hair out wondering why it isn't working. :D

Basicly I am thinking it would look something like this, but just want to be sure. . .

function displaydata() //opens new window and displays stored data in table format
var showdata=window.open("","popup","width=700 height=500, toolbar, scrollbars, menu, resizable")
var data='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n'
data+='<title>Accumulated Data Results</title>'
data+='<style type="text/css">\n'
data+='.norm {\n'
data+='color: white;\n'
data+='font-style: normal;\n'
data+='font-weight: normal;\n'
data+='font-size: small;\n'
data+='font-family: Arial;\n'

And so on and so forth until I have filled the table using the loop you suggested and then closed out with the last </html> tag and what not. Now I realize that what I have above could all have been smushed together, but I did it this way for ease of readability and what not. Anyways, if there is a problem adding this stuff, is their any sort of work around or am I just going to have to set my fonts and what not in a long-hand form?


01-24-2006, 02:19 AM
That's correct. You can add anything to it just like in any other web page. You can also link to an external CSS/Javascript so the page won't be that long and of course to make the CSS/Javascript reusable in all pages.