JavaScript Advanced Programming Learning Note Eighth Chapter--bom

Source: Internet
Author: User

1. Intermittent calls and timeout calls:

Timeout call: You need to use the SetTimeout () method of the Window object, which accepts two parameters: the code to execute and the time in milliseconds (that is, how many milliseconds to wait before executing the code). Where the first argument can be a string that contains JavaScript code (just like the string used in the eval () function), or it can be a function.

The second parameter is a number of milliseconds that indicate how long to wait, but the code specified after that time is not necessarily executed. JavaScript is an interpreter for a single-threaded program, so only a piece of code can be executed within a certain amount of time. To control the code to execute, there is a JavaScript task queue. These tasks are performed in the order in which they are added to the queue. The second parameter of SetTimeout () tells JavaScript to add too much time to the queue for the current task. If the queue is empty, the added code executes immediately, and if the queue is not empty, it waits until the previous code finishes executing. (normal execution is calculated as usual)

Intermittent invocation:
Calling the SetInterval () method also returns an intermittent invocation ID that can be used to cancel intermittent calls at some point in the future. To cancel an intermittent call that has not yet been performed, you can use the Clearinterval () method and pass in the corresponding intermittent invocation ID. Canceling an intermittent call is much more important than canceling the timeout call because, without intervening, the intermittent call will be performed until the page is unloaded.

2. System dialog box:
Alert (): Warning dialog box, for example: Alert ("Hello world!")

Confirm (): confirmation dialog box, for example:

1 if (Confirm ("Is you sure?") ) {2 alert ("I ' m so glad you ' re sure!") ); 3 Else {4 alert ("I ' m sorry to hear you ' re not sure.") ); 5 }

Prompt (): This is a "hint" box that prompts the user to enter some text. In addition to displaying the OK and Cancel buttons in the Prompt box, a text input field is displayed where the user can enter content. The prompt () method accepts two parameters: the text prompt to be displayed to the user and the default value of the text input field (which can be an empty string).

1 var result = Prompt ("What is your name?", ""); 2 if NULL {3 alert ("Welcome," + result); 4 }

Find (): Lookup, Window.find ()

Print (): printing, Window.print ()

3.location objects: Provides information about the documents loaded in the current window and provides some navigational features. The Location object is a very special object because it is both a property of the Window object and
The properties of the Document object; in other words, window.location and document.location refer to the same object.

4. Location.search returns everything from the question mark to the end of the URL, but there is no way to access each of these query string parameters individually.

5.location objects can change the browser's location in many ways. The first and most common way is to use the Assign () method and pass a URL to it. This allows you to immediately open a new URL and generate a record in your browser's history. If you set location.href or window.location to a URL value, the Assign () method is also called with that value. The following code is completely equivalent:

1 window.location = "http://www.wrox.com"; 2 location.href = "http://www.wrox.com";

The 6.location object also has a number of properties that are as follows:

7. When a URL is modified in either of these ways, a new record is generated in the browser's history, so the user navigates to the previous page by clicking the Back button. To disable this behavior, you can use the Replace () method. This method accepts only one parameter, which is the URL to navigate to, and results in a change in the browser location, but does not generate a new record in the history. After calling the replace () method, the user cannot go back to the previous page.
For example: location.replace ("http://www.wrox.com/");

8.reload () Method: The function is to reload the currently displayed page, and if you call reload () without passing any parameters, the page will reload in the most efficient way. This means that if the page has not changed since the last request
Changes, the page reloads from the browser cache. If you want to force a reload from the server, you need to pass the parameter true for the method as follows.

9.navigator object: A fact standard that identifies the client browser, which is common to all JavaScript-enabled browsers, and navigator objects in each browser have their own properties.

For non-IE browsers, you can use the plugins array to achieve this purpose. Each item in the array contains the following properties.

  • Name: Plug-in names.
  • Description: Description of the plugin.
  • FileName: The file name of the plugin.
  • Length: The number of MIME types processed by the plugin.
  • 1 //Detect Plug-ins (not valid in IE)2 functionHasplugin (name) {3Name =name.tolowercase ();4  for(vari=0; i < navigator.plugins.length; i++){5 if(navigator. plugins [I].name.tolowercase (). IndexOf (name) >-1){6 return true;7 }8 }9 return false;Ten } One //Detect Flash AAlert (Hasplugin ("Flash")); - //Detect QuickTime -Alert (Hasplugin ("QuickTime"));

  • The only way to detect plug-ins in IE is to use a proprietary ActiveXObject type and try to create an instance of a particular plug-in. IE is implemented as a COM object, and the COM object is identified by a unique identifier. Therefore, to check a particular plug-in, you must know its COM identifier. For example, the identifier for Flash is Shockwaveflash.shockwaveflash. Once you know the unique identifier, you can write a function like the following to detect if the plugin is installed in IE.
    1 //detection of plugins in IE2 functionHasieplugin (name) {3 Try {4 NewActiveXObject (name);5 return true;6}Catch(ex) {7 return false;8 }9 }Ten //Detect Flash OneAlert (Hasieplugin ("Shockwaveflash.shockwaveflash")); A //Detect QuickTime -Alert (Hasieplugin ("Quicktime.quicktime"));

10. Registration handler: The Navigator object has new Registercontenthandler () and Registerprotocolhandler () methods.

11.screen objects

12.history objects:

Use the Go () method to jump anywhere in the user's history, either backwards or forwards. A method takes a parameter that represents an integer value for the number of pages that jump backwards or forwards. A negative number indicates a backward jump (similar to clicking the browser's Back button), and a positive number indicates a forward jump (similar to clicking the browser's Forward button). You can also pass a string argument to the Go () method, where the browser jumps to the first one in the history that contains the string.
Position-may be back or forward, depending on which location is nearest. If the history does not contain the string, then this method does nothing. For example: history.go ("wrox.com"); Jump to the nearest wrox.com page


You can use the two shorthand methods back () and forward () instead of Go (), and Forward () represents the forward.

The length property of history represents the number of historical stores.

JavaScript Advanced Programming Learning Note Eighth Chapter--bom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.