Java Script

Posted On February 23, 2010

Filed under web application

Comments Dropped leave a response


Redirect a page using confirm :

<script type=”text/Javascript”>
var url=”http://www.somesite.com&#8221;;
var redirect=confirm(“Do you want to be redirected to “+url);
if(redirect)
{
window.location.href=url;
}
</script>

Alert – “On Click”

You can place the JavaScript alert() function directly into a button element, then use the ‘onclick’ event to trigger it. Like this:

<input type=”button” value=”Click me…” onclick=”alert(‘Thanks… I feel much better now!’);” />

Alert – Before Page Loads

<html>
<head>
<body>
<div style=”text-align:center;padding:10px;”>
<h1>Amazing Web Page</h1>
<script type=”text/javascript”>
alert(‘But wait, there\’s more…’);
</script>
<p><a href=”JavaScript:self.close();”>Close This Page!</a></p>
</div>
</body>
</html>

Alert – After Page Loads

<html>
<head>
<script type=”text/javascript”>
function alertUser(msg) {
alert(msg);
}
</script>
</head>
<body onload=”alertUser(‘Welcome to this AMAZING web page!’)”>
<div style=”text-align:center;padding:10px;”>
<h1>Amazing Web Page.</h1>
<p><a href=”JavaScript:self.close();”>Close</a></p>
</div>
</body>
</html>

Alert – Within Another Function

<script language=”javascript” type=”text/javascript” >
function jumpto(x){

if (document.form1.jumpmenu.value != “null”) {
if (document.form1.jumpmenu.value != “http://www.quackit.com&#8221;) {
alert(‘Sorry to see you leaving Quackit. Hope to see you back soon!’);
}
document.location.href = x
}
}
</script>
<form name=”form1″>
<select name=”jumpmenu”
onChange=”jumpto(document.form1.jumpmenu.options[document.form1.jumpmenu.options.selectedIndex].value)”>
<option>Jump to…</option>
<option value=”http://www.quackit.com”>Quackit Homepage</option>
<option value=”http://www.zappyhost.com”>ZappyHost</option&gt;
<option value=”http://www.code-generator.net”>Code Generator</option>
<option value=”http://www.natural-environment.com”>Natural Environment</option>
<option value=”http://www.great-workout.com”>Great Workout</option>
</select>
</form>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s