Java Script Quick Tutorial
6. Creating windows (dynamic HTML)
Summary :
Opening a basic window :
Copy of the javascript code :
function BasicWindow()
{
newWindow=window.open("","displayWindow","menubar=yes")
newWindow.document.write
("<HEAD><TITLE>Message window</TITLE></HEAD>")
newWindow.document.write
("<CENTER><BIG><B>Hello,
world!</B></BIG></CENTER>")
}
Open a basic window :
Alert window ( with a formated message ) :
Copy of the javascript code :
function AlertWindow ( title, message )
{
//----- Open the window. (to be checked : titlebar=no)
newWindow =
window.open("","displayWindow","dependent,alwaysRaised=yes,menubar=no");
//----- Head
newWindow.document.write ( "<HEAD><TITLE>" + title +
"</TITLE></HEAD><br>" );
//----- Message
newWindow.document.write ( message );
newWindow.document.write ( '<script
LANGUAGE="JavaScript">g_returnCommand = ""</script>' );
newWindow.document.write ( '<form method="POST"
name="Form1">' );
newWindow.document.write ( '<p><br><center>' );
newWindow.document.write ( '<input type="button" value=" OK
" name="buttonOk" ' );
newWindow.document.write ( 'onclick="g_returnCommand=' +
"'buttonOk'" + ';">' );
newWindow.document.write ( '</center></p></form>' );
//----- Waiting for user to click a button.
while ( newWindow.g_returnCommand == "" ) { }
var result = newWindow.g_returnCommand ;
//----- Closing the window.
newWindow.close();
return result ;
}
Open an alert window ( with a basic message ) :
onClick="alert( 'result = ' +
alertWindow('Basic message', 'Hello, world!' ) );"
Open an alert window ( with a formatted message ) :
onClick="alert( 'result = ' +
alertWindow('Formatted message', '<center><big><b>Hello,
world!</b></big></center>' ) );"
Confirmation window ( with a formated message ) :
Copy of the javascript code :
function AlertWindow ( title, message )
{
//----- Open the window. (to be checked : titlebar=no)
newWindow =
window.open("","displayWindow","dependent,alwaysRaised=yes,menubar=no");
//----- Head
newWindow.document.write ( "<HEAD><TITLE>" + title +
"</TITLE></HEAD><br>" );
//----- Message
newWindow.document.write ( message );
newWindow.document.write ( '<script
LANGUAGE="JavaScript">g_returnCommand = ""</script>' );
newWindow.document.write ( '<form method="POST"
name="Form1">' );
newWindow.document.write ( '<p><br><center>' );
newWindow.document.write ( '<input type="button" value=" OK
" name="buttonOk" ' );
newWindow.document.write ( 'onclick="g_returnCommand=' +
"'buttonOk'" + ';">' );
newWindow.document.write ( '<input type="button" value="
Cancel " name="buttonCancel" ' );
newWindow.document.write ( 'onclick="g_returnCommand=' +
"'buttonCancel'" + ';">' );
newWindow.document.write ( '</center></p></form>' );
//----- Waiting for user to click a button.
while ( newWindow.g_returnCommand == "" ) { }
var result = newWindow.g_returnCommand ;
//----- Closing the window.
newWindow.close();
return result ;
}
Open a confirm window ( with a basic message ) :
onClick="alert( 'result = ' +
ConfirmWindow('Basic message', 'Confirm this message ?!' ) );"
Open a confirm window ( with a formatted message ) :
onClick="alert( 'result = ' +
ConfirmWindow('Formatted message', '<center><big><b>Confirm this message
? </b></big></center>' ) );"