PDA

View Full Version : Open new window with content



blkskull
Jan 19th, 2007, 06:53 PM
Is it possible to open a new window and then add a button and a text box, if so how?

Thanks

ess
Jan 19th, 2007, 08:05 PM
Here is an example,


<script type="text/javascript">
function openPopUp() {
var h = 400; // popup hight
var w = 600; // popup width
var winTop = ( screen.height - h ) / 2; // position x coordinate of popup
var winLeft = ( screen.width - w ) / 2; // position y coordinate of popup

// the following is all the options you want to use
// for the popup...edit as you see fit
var opt = 'top='+winTop+',left='+winLeft+',scrollbars=yes,menubar=no,height=' + h + ',width=' + w + ',resizable=no,toolbar=no,location=no,status=no';

// and then open your window.
var newWindow = window.open( '','',opt);
newWindow.document.write( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" \n\t"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' );
newWindow.document.write( '<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n<title>TITLE_HERE</title>\n' );
newWindow.document.write( '<link href="' + CSS_FILE_HERE+ ' " rel="stylesheet" type="text/css"/>\n</head>\n<body>\n' );
newWindow.document.write( "<h1>POPUP</h1>" );
newWindow.document.write( "\n</body>\n</html>" );
newWindow.document.close();
newWindow.focus();
}
</script>

IF you have a document already defined, than you can use this syntax instead


window.open( file_name.html, "file title", WINDOW_OPTIONS );
Cheers,
Ess

david_kw
Jan 19th, 2007, 08:09 PM
Yes it is possible. A simple way is like this.



function openPopup(title_str) {
html_src = "<html><head><title>" + title_str + "</title></head><body>" +
"<form><input type='text' /><input type='submit' value='Enter' />" +
"</body></html>";

popup_win=window.open('');
popup_win.document.open();
popup_win.document.write(html_src);
popup_win.document.close();
}


david_kw

OMG I need to code faster! :)

blkskull
Jan 19th, 2007, 08:45 PM
Thankyou both for your help.