Im having a few problems with a script. The idea is to define a DIV on a page (out of the body of the document and not shown on the page) containing some HTML to be displayed in a popup window. The DIV id tag is sent to this function, which retrieves the DIV from the page via document.getElementByID().
The function then finds an appropriate size for the popup window based on the size of the DIV and sets up the window properties string accordingly. It then opens a new window with this string, writes some HTML into the new window, giving the body the “popup_body” id, and inserts the DIV using
doc.getElementById(“popup_body”).appendChild(element);
Now it gets as far as opening a window, but the width and height are given as 20, and i get a blank window. All the HTML is there when i click view source, apart from the elment sent to the function. Scryptix says the above appendChild line has a syntax error on it, but i dont see it…? What could i be doing wrong? I have a similar script for images, which works perfectly…
Thanks in advance for any help
-Jonskichov (code follows)
[FONT=Courier New]function html_popup(element_id) {
var element = document.getElementById(element_id);
//get correct width and height for window, making sure it isn’t bigger than the screen resolution//
var winWidth = element.style.width;
var winHeight = element.style.height;
var wThreshold = screen.availWidth;
var hThreshold = screen.availHeight;
winWidth = winWidth + 20;
if(winWidth > wThreshold) {
winWidth = wThreshold;
}
winHeight = winHeight + 20;
if(winHeight > hThreshold) {
winHeight = hThreshold;
}
alert(“w ” + winWidth + ” h ” + winHeight);
//open new window and make correct size//
var settingsString = “toolbar=no,” +
“location=no,” +
“directories=no,” +
“status=no,” +
“menubar=no,” +
“scrollbars=yes,” +
“resizable=yes,” +
“width=” + winWidth + “,” +
“height=” + winHeight;
var newWin = window.open(“”, “_blank”, settingsString, “false”);
//write html and add element//
var doc = newWin.document;
doc.open();
doc.writeln(“<html>n”);
doc.writeln(” <head>n”);
doc.writeln(” <title> a title </title>n”);
doc.writeln(” <link rel=”stylesheet” type=”text/css” href=”style.css”>n”);
doc.writeln(” </head>n”);
doc.writeln(” <body id=”popup_body”>n”);
doc.writeln(” </body>n”);
doc.write(“</html>n”);
doc.close();
doc.getElementById(“popup_body”).appendChild(element);
//focus new window//
newWin.focus();
}[/FONT]