How to use window.open and window.close in JavaScript

Source: Internet
Author: User

Sometimes, we want to achieve a <a> through JS the effect of a new tab, at this time we think of the window.open method implementation. So how exactly should window.open be used?

We know that window.open can open a new window or tab (which is usually related to the browser's setup options), load the specified URL into a new or existing window, and return the Window object that represents it. Window.close can close the window, but can only automatically close JS open window, if you want to close other windows, you must prompt the user to determine or cancel the operation (this browser-related, measured IE need to be prompted to turn off; other browsers do not allow automatic shutdown).

We can open the window directly using window.open () and close the window using Window.close ()

<! DOCTYPE html>  

window.open (URL, name[, property][, Boolean]) requires four parameters:

First parameter URL: The URL of the document displayed in the new window, if omitted or empty, uses ' About:blank '

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

Second parameter name: The name of the new window, which can be used with target and, if omitted, will use ' _blank ' (here is a brief introduction: _parent and _top,_parent refer to the Direct parent window, _top refers to the top-level ancestor window)

The third parameter protery: an optional parameter separated by commas, containing the window size and various properties. If omitted, the default size and standard UI components are used (explicit invocations are more like open windows rather than labels). This parameter is non-standard, and the HTML5 specification also advocates that browsers ignore it.

Fourth argument Boolean: Valid only if the second argument is named the existing window. Declares the URL specified by the first parameter, replacing the current entry for the window's browsing history.

Window.opener refers to the original window, if not, to null.

<! DOCTYPE html>  
Related Article

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.