Home > Web Front-end > JS Tutorial > window.open in javascript opens a new window (different name) in the original window_javascript skills

window.open in javascript opens a new window (different name) in the original window_javascript skills

WBOY
Release: 2016-05-16 15:32:17
Original
2083 people have browsed it

I recently made a JSP webpage that required opening IE without a menu toolbar, so I thought of using window.open to open it. However, I found that if the previously opened form is not closed, when opening a form, a new form will be opened on the previously opened form, so that the previous window will be replaced. After searching for information and testing, we found that if the form name specified when opening the form has the same name as the current form, it will be opened on that form. For example, the following situation:

window.open("view_svg.jsp?ukey=<%=ukey%>&itemID=<%=itemID%>&charset=UTF-8","newWindow","height='100%' , width='100%',toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,status=no");
Each form opened in this way is opened in a form named newWindow.

Note: The name and title of the form are different.

1.window.open(urlStr,'_blank','');

_blank parameter means opening a new window.

2. You can also use the following method to make the window have a different name each time it is opened.

<%
Random rd = new Random();
int i = rd.nextInt(100)+1;
String ranStr = String.valueOf(i);
%>
<script type="text/javascript">
function doclose(){
 var currnwin = window.open("view_svg.jsp&#63;ukey=<%=ukey%>&itemID=<%=itemID%>&charset=UTF-8","<%=ranStr%>","height='100%', width='100%',toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,status=no");
window.opener=null;
 window.close();
 window.focus();
}
</script>

Copy after login

Now I will introduce to you how to use javascript window.open to open a new window

The open() method can find an existing or newly created browser window.

Grammar:

window.open([URL], [window name], [parameter string])

Parameter description:

URL: Optional parameter, the URL or path of the web page to be displayed in the window. If this parameter is omitted, or its value is an empty string, no document will be displayed in the window.

Window name: Optional parameter, the name of the opened window.

1. The name consists of letters, numbers and underline characters.
2. "_top", "_blank", "_selft" are names with special meanings.
​ ​ _blank: Display the target page in a new window
​​​​_self: Display the target web page in the current window
​ ​ _top: Display the target web page in the upper window of the frame web page
3. Only one window with the same name can be created. If you want to create multiple windows, the names cannot be the same.
​ 4.name cannot contain spaces.

Parameter string: optional parameter, set window parameters, each parameter is separated by commas.

Parameter table:

For example: Open the http://www.baidu.com website, the size is 300px * 200px, no menu, no toolbar, no status bar, and a scroll bar window:

<script type="text/javascript"> window.open('http://www.baidu.com','_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes')
</script>
Copy after login

Friendly reminder: Be sure to pay attention to browser compatibility issues here.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template