JS Popup Window


JS has several way to popup window and box to interact with user. Functions include window.open(), window.confirm(), window.alert(), window.prompt().

The simplest, popup an alert box:

Window.alert("alert box is a simple popup box.");



Popup a new window:

var w = window.open("","","width=500, height=80");
w.document.write("EndMemo.com javascript Tutorial");



close() method will close an open window:

var w = window.open("","","width=500, height=80");
w.document.write("EndMemo.com javascript Tutorial");
w.close();



Popup a confirm box. Comfirm box returns true if the user clicks "OK", otherwise false:

var c = windwo.confirm("You like this tutorial?");
if (c) alert("Thank you.");
else alert("OK, you don't like this.");



Popup a prompt box. Prompt box returns the input value if user clicks "OK" or false. Following example will prompt a box, if you input "Yes" then click "OK", an alert box will popup, otherwise alert box will not popup:

var c = window.prompt("You like this?","");
if (c != null && c=="Yes") alert("Thank you.");



To keep it simple, you do not need to write the full function name, for example, window.confirm() can be written as confirm().

endmemo.com © 2024  | Terms of Use | Privacy | Home