Creating New Window

To create a new window you use function open(), to close window function close() Here is an example.

Java Script Code:
In header we define two functions:
<script language="JavaScript">
<!--
var secWindow 
//Creating new window
function openW(){
	secWindow = window.open("picture.html","","HEIGHT = 400, WIDTH=600")
}
//Closing new window
function closeW() {
	if(secWindow) {
		secWindow.close()
		secWindow = null
	}
}
//-->
</script>

In body we call two functions:
<FORM>
<INPUT TYPE = "button" VALUE = "create new window" onClick = "openW()">
<INPUT TYPE = "button" VALUE = "close window" onClick = "closeW()">
</FORM>

Window Methods

there are three window methods: alert(), confirm() and prompt().

alert() method

This method displays a widow with a single message:

Java Script Code:
In header we define a function:
<script language="JavaScript">
<!--
function alertW() {
	window.alert("This is alert window!")
}
//-->
</script>
In body we call this function:
<FORM>
<INPUT TYPE = "button" VALUE = "ALERT!" onClick = "alertW()"> 
</FORM>

confirm() method

This method displays a yes/no dialog and returns boolean value:

Java Script Code:
In header we define a function:
<script language="JavaScript">
<!--
function confirmW() {
	if(window.confirm("Are you sure you want to go to main page?")) {
		location.href="index.html"
	}
}
//-->
</script>
In body we call this function:
<FORM>
<INPUT TYPE = "button" VALUE = "CONFIRM" onClick = "confirmW()">
</FORM>

prompt() method

This method displays a dialog where user can input some data and returns it:

Java Script Code:
In header we define a function:
<script language="JavaScript">
<!--
function promptW() {
	var answer = window.prompt("What is your name?","ququqa","")
	if(answer) { window.alert("Hello "+answer+"!")}
}
//-->
</script>
In body we call this function:
<FORM>
<INPUT TYPE = "button" VALUE = ""PROMPT" onClick = "promptW()">
</FORM>


Back to Java script list


Back to main page