JavaScript advanced programming Reading Notes (15th) JavaScript in the browser

Source: Internet
Author: User

Window object

Window operations
Window objects are very useful for operating browser windows. developers can move or adjust the size of browser windows. You can perform these operations in four ways:
MoveBy (dx, dy): Move dx pixels horizontally from the browser window to the current position, and move dy pixels vertically. The dx value is the negative shift left, and dy is the negative move up.
MoveTo (x, y): Move the browser window so that its upper left corner is located at (x, y) of the user screen. You can use a negative number, but this will remove some windows from the visible area of the screen.
ResizeBy (dw, dh): adjusts the width of the window to dw pixels and the height to dy pixels relative to the current size of the browser window. When dw and dy are negative, the window is reduced.
ResizeTo (w, h): Adjust the window width to w, and the height to h. A negative number is not allowed.

Note: FireFox and Chrome do not allow this operation by default. You must change it in the security settings.

Effect (in IE browser ):
<! DOCTYPE html> <pead> <meta charset = "UTF-8"/> <title> JavaScript window operation </title> </pead> <body> <input type =" button "onclick =" moveByF () "value =" moveBy "/> <input type =" button "onclick =" moveToF () "value =" moveTo "/> <input type =" button "onclick =" resizeByF () "value =" resizeBy "/> <input type =" button "onclick =" resizeToF () "value =" resizeTo "/> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Navigate to and open a new window

Use window to navigate and open a new window. the open () method, which accepts four parameters, namely, the URL of the page to load the new window, the name of the new window, feature string and description whether to replace the Boolean value of the currently loaded page with the newly loaded page. Generally, only the first three parameters are used. The last parameter is valid only when window. open () cannot open a new window.

The optional values of the third parameter are as follows:

Top = y coordinate of the pixels window.

Left = pixels The x coordinate of the window. In pixels.
Height = pixels The height of the window document display area. In pixels.
Width = pixels The width of the document display area of the window. In pixels.
Resizable = yes | no Whether the window size is adjustable. The default value is yes.
Scrollable = yes | no Whether to display the scroll bar. The default value is yes.
Location = yes | no Whether to display the address field. The default value is yes.
Status = yes | no Whether to add a status bar. The default value is yes.
Toolbar = yes | no Whether to display the toolbar of the browser. The default value is yes.

Feature strings are separated by commas. Therefore, there cannot be spaces after commas or equal signs.

Example:
<! DOCTYPE html> <pead> <meta charset = "UTF-8"/> <title> JavaScript opens a new window </title> </pead> <body> <input type = "button" value = "open window" onclick = "open_win () "> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Document Object

You can use the open, write, and close methods of document to write content to the newly opened window, as shown below:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function run (){
Var oNewWin = window. open ("about: blank", "newwindow", "height = 300, width = 400 ");
ONewWin.doc ument. open ();
ONewWin.doc ument. write ("ONewWin.doc ument. close ();
}
</Script>
<Input type = 'button 'value = 'run' onclick = 'run () '/>


Location object

The location object can be used to parse the URL, for example, the URL is: http://www.jb51.net/2012/04/14/2446762.html#top? Id = 1, then:
Hash: # top
Host: www.cnblogs.com
Hostname: www.cnblogs.com
Href: http://www.jb51.net/2012/04/14/2446762.html#top? Id = 1
Pathname:/artwl/archive/2012/04/14/2446762 .html
Port: blank
Protocol: http:
Search :? Id = 1

Author: Artwl
Source: http://artwl.cnblogs.com

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.