12345678910111213141516171819202122 |
In web development, we often need to obtain key-value pairs such as Id=5&search=ok for this type of URL;//through location, we can write a function to get one by one; function Getargs () {// Create an array of key-value pairs; var args = [];//removal number; var qs = location.search.length>0?location.search.substring (1): ";//Press & String split fraction group; var items = Qs.split (' & '); var item = NULL, name = NULL, value = null;//traversal for (var i = 0; i<items.length; i++ {item = items[i].split (' = '); name = decodeURIComponent (item[0]);//Because the query string is encoded by the browser; value = decodeURIComponent (Item[1]) ;//each query string parameter becomes a property of the Args object;//The key-value pair is stored in the array; args[name] = value;} return args;} var args = Getargs (); alert (args[' id '); Gets the value corresponding to the ID in the URL, as follows: Location.assign (' http://www.baidu.com '); Jumps to the specified url;2 Location.reload (); The most efficient reload, it is possible to load from the cache; Location.reload (TRUE); Force load, reload from server source; 5 Locatioin.replace (' http://www.baidu.com '); On this page to jump to the Baidu page, and can avoid the history of jump to produce;Three History objects The history object is the property of the Window object, which holds the record of the user's Internet access, from the moment the window is opened; (1). Properties of the History object The number of records in the length history object; (2). Method of the History object Back () go to the browser history bar currently a URL, similar to backward; Forward () go to the browser history entry next URL, similar to forward; The Go (NUM) browser is forward or backward in the history object; Copy the code code as follows: function back () { History.back (); } function forward () { History.forward (); } function Go (num) { History.go (num); } PS: Can be judged by history.length = = 0, to get a historical record;Summary of Four The browser object model (BOM) is based on the Window object, which represents the browser window and the visible area of the page. The Window object is also a global object in ECMAScript, so all global variables and functions are its properties, and all native constructors and other functions exist under its namespace; (1). Use the Location object to programmatically access the browser's navigation system, set the corresponding properties, you can modify the URL of the browser piecemeal or in a holistic manner; (2). Call the Replace () method to navigate to a new URL that replaces the currently displayed page in the browser history; (3). Screen object: Holds information about the client display, which is generally used only for site analysis; (4). History object: A small gap has been opened in order to access the browser's historical record, in which the developer can judge the number of historical records, or navigate backward or forward to any page in the history record; Two::: What is a BOM?
- The BOM is an abbreviation for the browser object model.
- BOM provides an object that is independent of the content and interacts with the browser window
- Because the BOM is primarily used to manage the communication between Windows and Windows, its core object is window
- A BOM is composed of a series of related objects, and each object provides many methods and properties
- BOM lack of standards, the standardization of JavaScript Grammar Organization is ECMA,DOM standardization Organization is a (whatwg,webhypertextapplicationtechnologyworkinggroup-- Web Hypertext Application Technical team is currently working to promote the standardization of the BOM)
- The BOM was originally part of the Netscape browser standard
What can I do with the BOM?The BOM provides some ways to access the Window object, which we can use to move the window position, change the window size, open a new window and close the window, pop up a dialog, navigate and get some information about the customer such as: Browser brand version, screen resolution. But the most powerful feature of the BOM is that it provides an entry---document object that accesses an HTML page so that we can use the powerful features of the DOM through this portal!!! The Window object is the top-level (core) object of the BOM, all of which are extended by it or are called child objects of the window. Because window is the top-level object, you can call its child objects without displaying the indicated window object, for example, the following two lines of code are the same: document.write ("BOM"); Window.document.write ("BOM");
Window-the Window object is the core of all objects in the BOM. The Window object represents the entire browser window, but does not have to represent what it contains. In addition, window can be used to move or adjust the size of the browser it represents, or to have other effects on it. Any global function or variable in JavaScript is a property of window Window Sub-Object
- Document Object
- Frames Object
- History Object
- Location Object
- Navigator Object
- Screen Object
Window Object Relationship Properties
- Parent: If the current window is a frame, point to the frame that contains the frame's window
- Self: points to the current Window object, with window consent. (Window object)
- Top: If the current window is frame, point to the Window object that contains the top-level of the frame
- window: points to the current Window object, with self consent.
- Opener: When the window is opened with JavaScript, point to the person who opened it (opener)
Window Object Positioning properties
- IE provides window.screenleft and Window.screentop objects to determine the position of the window, but does not provide any way to determine the window size. With the Document.body.offsetWidth and Document.body. offsetheight properties, you can get the size of the viewport (the area that displays the HTML page), but they are not standard properties.
- Mozilla provides Window.screenx and Window.screeny properties to determine the position of the window. It also provides the window.innerwidth and Window.innerheight properties to determine the size of the viewport, Window.outerwidth and Window.outerheight properties to determine the size of the browser window itself.
Method of the Window object
-
Form Control
-
moveby (x, y)-Moves the form's x pixels horizontally from the current position, moves the form y pixels vertically, X is negative, moves the form to the left, Y is negative, and moves the form up
-
moveTo (x, y)-Moves the upper-left corner of the form to the (x, y) point relative to the upper-left corner of the screen, and when a negative number is used as a parameter, the form moves out of the visible area of the screen
-
Resizeby (w,h)--relative to the current size of the form, the width adjusts to w pixels and the height of h pixels. If the argument is negative, the form is scaled down, whereas
the form
-
resizeto (w,h) expands--Adjusts the width of the form to w pixels and height to h pixels
-
Form Scroll Axis control
-
scrollTo (x, y)--if there is a scroll bar in the form, move the horizontal scroll bar to a position relative to the form's width of x pixels, and move the vertical scroll bar to a position relative to the form's Y-pixel height
-
Scrollby (x, y)-if there is a scrollbar, move the horizontal scroll bar to the position of x pixels relative to the current horizontal scroll bar (that is, move the X-pixel to the left), and move the vertical scroll bar to a position relative to the current vertical scrollbar height of y pixels (that is, move the Y-pixel down)
-
Form Focus Control
Focus
-
()--Causes the form or control to get focus
-
Blur ()--in contrast to the focus function, causes the form or control to lose focus
-
New Form
-
Open ()--Opens (pops up) a new form
Close
-
()--Close the form
-
Opener Property--a reference to the parent form in a new form, meaning "opener" in Chinese
Window.Open method Syntax window.open (URL, name, features, replace);
Open method Parameter Description
- URL--the URL to load the form into
- Name-a new form (destination, which will be used in the target property of the a tag to overwrite the form's contents with the name of the existing form). The Open function defaults to opening the form to the _blank pop-up of the target, so the page will open in a popup way
- Features-a string representing the attributes of the form, with each attribute in the string separated by commas
- Replace-A Boolean value that indicates whether the newly loaded page replaces the currently loaded page, which is usually not specified
The Open function features the parameter description and opens a new normal window if you do not use the third argument
Parameter name |
type |
Description |
Height |
Number |
Set the height of the form, not less than 100 |
Left |
Number |
Description creates the left coordinate of the form and cannot be a negative value |
Location |
Boolean |
Whether the form displays the Address bar, the default value is no |
Resizable |
Boolean |
Whether the form allows resizing by dragging edges, the default value is no |
ScrollBars |
Boolean |
Whether dragging is allowed inside the form when it is outside the window's visible range, the default value is no |
Toolbar |
Boolean |
Whether the form displays a toolbar, the default value is no |
Top |
Number |
Description creates the top coordinate of the form and cannot be a negative value |
Status |
Boolean |
Whether the form displays a status bar, the default value is no |
Width |
Number |
Create the width of the form, cannot be less than 100 |
each attribute in the attribute string is separated by commas, and no spaces are allowed between each attribute The Open method returns a reference to the Window object for a new form
-
dialog box
-
alert (str)-pop-up message dialog box (there is a OK button in the dialog box)
-
confirm (str)-Popup message dialog box (contains a "OK" button and "Cancel" button)
-
prompt (Str,defaultvalue)-Pop-up Message dialog Box (dialog box contains a "OK" button, "Cancel" button and a text input box), due to the different browser implementation, It is also best to provide an empty string if there is no second argument (the default value in the text box)
-
Status bar
-
Window.defaultstatus Property--Changes the default display of the browser status bar (when there is no other display in the status bar), the area at the bottom of the browser is called the status bar, which is used to display information to the user
-
Window.status Property--temporarily changes the display of the browser status bar
-
Time Wait and interval function
-
setTimeout ()--executes the specified code after pausing the specified number of milliseconds
-
cleartimeout ()--cancels the code that the specified settimeout function will execute
-
setinterval ()--interval Specifies the number of milliseconds to execute the specified code continuously
-
clearinterval ()--cancels the code that the specified setinterval function will execute
The settimeout and SetInterval methods have two parameters, the first parameter can be either a string or a function reference, the second parameter is the interval of milliseconds, and their return is a numeric ID that can be used for the corresponding clear method var tid = setTimeout ("Alert (' 1 ')", +); Alert (TID); Cleartimeout (TID); History object, navigating through browser historiesHistory object's properties: Length returns the number of URLs in the browser history list Methods of the History object
- Back () load the previous URL in the history list
- Forward () load the next URL in the history list
- Go (num) loads a specific page in the history list
Location ObjectProperties of the Location object
- Hash set or return the URL (anchor) starting with the pound sign (#)
- Host sets or returns the hostname and port number of the current URL
- Hostname Sets or returns the host name of the current URL
- HREF Sets or returns the full URL
- Pathname Sets or returns the path portion of the current URL
- Port Sets or returns the port number of the current URL
- Protocol the protocol that sets or returns the current URL
- Search Sets or returns a URL starting from a question mark (?) (Query section)
Method of the Location object
- Assign () loads the new document, which is the same as the HREF attribute that assigns a URL directly to the Location object.
- Reload () reloads the current document, if the method does not specify a parameter, or if the parameter is False, it uses the HTTP header if-modified-since to detect whether the document on the server has changed. If the document has changed, reload () will download the document again. If the document does not change, the method will load the document from the cache. This is exactly the same as when the user clicks the browser's Refresh button. If the parameter of the method is set to true, it bypasses the cache and re-downloads the document from the server, regardless of the last modification date of the document. This is exactly the same as when the user presses the refresh button of the browser while holding down shift.
- Replace () replaces the current document with a new document, and the Replace () method does not generate a new record in the history object. When you use this method, the new URL overwrites the current record in the history object.
Navigator ObjectNavigator properties of an object
- appCodeName return the code name of the browser
- AppName returns the name of the browser
- AppVersion returns the platform and version information of the browser
- Browserlanguage returns the language of the current browser
- Cookieenabled returns a Boolean value that indicates whether cookies are enabled in the browser
- Cpuclass returns the CPU level of the browser system
- OnLine returns a Boolean value indicating whether the system is in offline mode
- Platform returns the operating system platform running the browser
- Systemlanguage returns the default language used by the OS
- UserAgent returns the value of the user-agent header of the server sent by the client
- Userlanguage returns the natural language settings of the OS
Frame with multi-window communication child window with parent windowOnly the window that is opened by itself and using the Window.Open method can be accessed by JavaScript, and the window opened by the Window.Open method accesses the parent window through the Window.opener property. In the opener window, you can access the open window by the return value of the window.open Method! FrameworkWindow.frames collection: In a frameset or page containing an IFRAME tag, the Frames collection contains a reference to a window in a frame alert (frames.length);//The number of frames alert (frames[0].document.body.innerhtml);//use subscript directly to get a reference to the window in the frame //Not only can use subscript, You can also use the Name property of the frame tag alert (frames["frame1"].document.title);
You can also use an ID in a frameset to get a reference to a child window var frame1 =document.getelementbyid ("frame1");//This just gets the label var frame1win = frame1.contentwindow;// The Contentwindow of the Frame object contains a reference to the window //can also get a reference to the document in the frame var framedoc = frame1.contentdocument; alert (framedoc);//But IE does not support contentdocument properties
|