Example for Popup window code :
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<p>Popup Window:</p>
<p><a href="JavaScript:newPopup('http://www.njsss.wordpress.com');">Click Here</a></p>
</body>
</html>
JavaScript has three kind of popup boxes:
1.Alert box.2.Confirm box.
3.Prompt box.
1.Alert Box :
An alert box is often used if you want to make sure information comes through to the user.Syntax :
window.alert("Enter text here");
<script>
function myFunction()
{
alert("alert box!");
}
</script>
<input type="button" onclick="myFunction()" value="click here" />
2.Confirm Box :
A confirm box is often used if you want the user to verify or accept something.Syntax :
window.confirm("Enter text here");
Example :
<p>confirm box.</p>
<button onclick="myFunction()">click Here</button>
<p id="Test"></p>
<script>
function myFunction()
{
var x;
var r=confirm("Press a button confirm!");
if (r==true)
{
x="Thanks!";
}
else
{
x="Sorry!";
}
document.getElementById("Test").innerHTML=x;
}
</script>
3.Prompt Box
A prompt box is often used if you want the user to input a value before entering a page.Syntax :
window.prompt("sometext","defaultvalue");
Example :
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">click Here</button>
<p id="Test"></p>
<script>
function myFunction()
{
var x;
var person=prompt("Please enter your name","Steve");
if (person!=null)
{
x="Hello " + person + "Welcome to Bangalore";
document.getElementById("Test").innerHTML=x;
}
}
</script>
No comments:
Post a Comment