1.Status and defaultStatus
<img src="images/imgmap1.gif" usemap="#map1">
<map name="map1">
<area coords="0,0,50,20" href="info.html"
onmouseover="status='Visit our Information Center'; return true;">
<area coords="0,20,50,40" href="order.html"
onmouseover="status='Place an order'; return true;">
<area coords="0,40,50,60" href="help.html"
onmouseover="status='Get help fast!'; return true;">
</map>
2.Dialog
function warn_on_submit( )
{
alert("\n__Please be patient.");
}
var msg = "\nYou are about to experience the most\n\n" ;
if (confirm(msg))
location.replace("awesome_page.html");
else
location.replace("lame_page.html");
n = prompt("What is your name?", "");
document.write("<hr><h1>Welcome to my home page, " + n + "</h1><hr>");
3.Timeout and Interval
function display_time_in_status_line( )
{
var d = new Date( ); // Get the current time
var h = d.getHours( ); // Extract hours: 0 to 23
var m = d.getMinutes( ); // Extract minutes: 0 to 59
var ampm = (h >= 12)?"PM":"AM"; // Is it a.m. or p.m.?
if (h > 12) h -= 12; // Convert 24-hour format to 12-hour
if (h == 0) h = 12; // Convert 0 o'clock to midnight
if (m < 10) m = "0" + m; // Convert 0 minutes to 00 minutes, etc.
var t = h + ':' + m + ' ' + ampm; // Put it all together
defaultStatus = t; // Display it in the status line
setTimeout("display_time_in_status_line( )", 60000); // 60000 ms is one minute
}
4.Error
self.onerror = function( ) { return true; }
5.Navigator
var browser = new Object( );
browser.version = parseInt(navigator.appVersion);
browser.isNetscape = false;
browser.isMicrosoft = false;
if (navigator.appName.indexOf("Netscape") != -1)
browser.isNetscape = true;
else if (navigator.appName.indexOf("Microsoft") != -1)
browser.isMicrosoft = true;
6.Window Open and Close
var w = window.open("smallwin.html", "smallwin", "width=400,height=350,status=yes,resizable=yes");
window.close( );
7.Location
a representation of the URL of the document currently being displayed in that window.
function getArgs( ) {
var args = new Object( );
var query = location.search.substring(1); // Get query string
var pairs = query.split(","); // Break at comma
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value"
if (pos == -1) continue; // If not found, skip
var argname = pairs[i].substring(0,pos); // Extract the name
var value = pairs[i].substring(pos+1); // Extract the value
args[argname] = unescape(value); // Store as a property
// In JavaScript 1.5, use decodeURIComponent( ) instead of escape( )
}
return args; // Return the object
}
var args = getArgs( ); // Get arguments
if (args.x) x = parseInt(args.x); // If arguments are defined...
if (args.y) y = parseInt(args.y); // override default values
if (args.w) w = parseInt(args.w);
if (args.h) h = parseInt(args.h);
if (args.dx) dx = parseInt(args.dx);
if (args.dy) dy = parseInt(args.dy);
if (args.interval) interval = parseInt(args.interval);
8.History
<script>
// The function is invoked by the Back button in our navigation bar
function go_back( )
{
// First, clear the URL entry field in our form
document.navbar.url.value = "";
// Then use the History object of the main frame to go back
parent.frames[0].history.back( );
// Wait a second, and then update the URL entry field in the form
// from the location.href property of the main frame. The wait seems
// to be necessary to allow the location.href property to get in sync.
setTimeout("document.navbar.url.value = parent.frames[0].location.href;",
1000);
}
// This function is invoked by the Forward button in the navigation bar;
// it works just like the previous one
function go_forward( )
{
document.navbar.url.value = "";
parent.frames[0].history.forward( );
setTimeout("document.navbar.url.value = parent.frames[0].location.href;",
1000);
}
// This function is invoked by the Go button in the navigation bar and also
// when the form is submitted (when the user hits the Return key)
function go_to( )
{
// Just set the location property of the main frame to the URL
// the user typed in
parent.frames[0].location = document.navbar.url.value;
}
</script>
<!-- Here's the form, with event handlers that invoke the functions above -->
<form name="navbar" onsubmit="go_to( ); return false;">
<input type="button" value="Back" onclick="go_back( );">
<input type="button" value="Forward" onclick="go_forward( );">
URL:
<input type="text" name="url" size="50">
<input type="button" value="Go" onclick="go_to( );">
</form>
没有评论:
发表评论