Home  >  Article  >  Web Front-end  >  Summary of JavaScript pop-up window methods_javascript skills

Summary of JavaScript pop-up window methods_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:39:511477browse

The examples in this article summarize the commonly used JavaScript pop-up window methods for your comparison and reference. I hope it will be helpful to everyone. The detailed method is as follows:

1. Refresh the webpage without prompting:

Have you noticed that when refreshing some web pages, a prompt window will pop up. Click "OK" to refresh.
Some pages will not prompt, and will be refreshed directly without popping up a prompt window.
If the page does not have a form,
The prompt window will not pop up
If the page has a form,
a)0a49d8328ba1b67146975e617cc81251
A prompt window will pop up
b)012a484319de2c757cb918250a0098ad
Will not pop up

2. How to refresh the page using javascript:

window.location.reload();

Use the pop-up window popped up by window.open() to refresh the parent window

window.opener.location.reload()

Use window.showDialog to pop up a modal window

window.dialogArguments.location.reload();

3.javascript pop-up window code:
window.open() method:
window.open() support environment: JavaScript1.0 /JScript1.0 /Nav2 /IE3 /Opera3
Basic syntax:

window.open(pageURL,name,parameters) 

Among them:
pageURL is the sub-window path
name is the child window handle
parameters are window parameters (each parameter is separated by commas)

Example:

<SCRIPT> 
<!-- 
window.open ('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') 
//写成一行 
--> 
</SCRIPT>

After the script is run, page.html will be opened in a new window with a width of 100, a height of 400, 0 pixels from the top of the screen, 0 pixels from the left of the screen, no toolbar, no menu bar, and no scrolling. Bar, not resizable, no address bar, no status bar.
Please compare.

The above example involves several commonly used parameters. In addition, there are many other parameters, please see 4.


Various parameters
Among them, yes/no can also use 1/0; pixel value is a specific value, unit pixel.

Parameter | Value range | Description
| |
alwaysLowered | yes/no | The specified window is hidden behind all windows
alwaysRaised | yes/no | The specified window is suspended above all windows
depended | yes/no | Whether to close at the same time as the parent window
directories | yes/no | Whether the directory bar of Nav2 and 3 is visible
height | pixel value | window height
hotkeys | yes/no | Set a safe exit hotkey in a window without a menu bar
innerHeight | pixel value | Pixel height of the document in the window
innerWidth | pixel value | Pixel width of the document in the window
location | yes/no | whether the location bar is visible
menubar | yes/no | Whether the menu bar is visible
outerHeight | pixel value | Set the pixel height of the window (including decorative borders)
outerWidth | pixel value | Set the pixel width of the window (including decorative borders)
resizable | yes/no | Whether the window size is resizable
screenX | pixel value | The length of the window in pixels from the left edge of the screen
screenY | pixel value | The length of the window in pixels from the upper border of the screen
scrollbars | yes/no | Whether the window can have scroll bars
titlebar | yes/no | Whether the window title bar is visible
toolbar | yes/no | Whether the window toolbar is visible
Width | pixel value | Pixel width of the window
z-look | yes/no | Whether the window floats above other windows after it is activated

function ShowDialog(url) {
  var iWidth=300; //窗口宽度
  var iHeight=200;//窗口高度
  var iTop=(window.screen.height-iHeight)/2;
  var iLeft=(window.screen.width-iWidth)/2;
  window.open(url,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,
Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
 }


window.showModalDialog method:

Basic introduction:

showModalDialog() (IE 4 supported)
showModelessDialog() (supported by IE 5)
The window.showModalDialog() method is used to create a modal dialog box that displays HTML content.
The window.showModelessDialog() method is used to create a modeless dialog box that displays HTML content.

How to use:

vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])

参数说明:

sURL--
必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments--
可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures--
可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
1.dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
2.dialogWidth: 对话框宽度。
3.dialogLeft: 离屏幕左的距离。
4.dialogTop: 离屏幕上的距离。
5.center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
6.help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
7.resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
8.status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
9.scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。

下面几个属性是用在HTA中的,在一般的网页中一般不使用。

10.dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
11.edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
12.unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。

参数传递:

(1).要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如:
-------------------------------
parent.htm页面:

<script>
var obj = new Object();
obj.name="jb51";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>

modal.htm页面:

<script>
var obj = window.dialogArguments
alert("您传递的参数为:" + obj.name)
</script>

(2)可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:

parent.htm页面代码:

<script>
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
<script>
window.returnValue="http://www.jb51.com";
</script>

例子:

function ShowDialog(url) {
  var iWidth=300; //窗口宽度
  var iHeight=200;//窗口高度
  var iTop=(window.screen.height-iHeight)/2;
  var iLeft=(window.screen.width-iWidth)/2;
  window.showModalDialog(url,window,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;
dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no");
 }

注意这里的第二个参数,window

4.模式窗口数据不刷新(缓存)问题

在jsp页面加入如下语句

<%
   response.setHeader("Pragma","No-Cache");
   response.setHeader("Cache-Control","No-Cache");
   response.setDateHeader("Expires", 0);
%>

5.模式窗口中,链接弹出新窗口问题:

◎_blank,在新浏览器窗口中打开链接文件。

◎_parent,将链接的文件载入含有该链接框架的父框架集或父窗口中。如果含有该链接的框架不是嵌套的,则在浏览器全屏窗口中载入链接的文件,就象_self参数一样。

◎_self,在同一框架或窗口中打开所链接的文档。此参数为默认值,通常不用指定。

◎_top,在当前的整个浏览器窗口中打开所链接的文档,因而会删除所有框架。

在9c3bca370b5104690d9ef395f2c5f8d1和6c04bd5ca3fcae76e30b72ad730ca86d间加入50e4aea961872c99fc549888c41dc48a

6.无提示关闭页面的方法:

function CloseWin(){
  var ua = navigator.userAgent; var ie = navigator.appName=="Microsoft Internet Explorer"&#63;true:false;
  if(ie){
 var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))));
  if( IEversion< 5.5){
  var str = '';
  document.body.insertAdjacentHTML("beforeEnd", str);
   document.all.noTipClose.Click();
  } else {
   window.opener =null; window.close();
  }
 }else{
 window.close()
 }
}

感兴趣的读者可以调试一下上述方法,相信会给大家带来一定的启发与帮助。

Statement:
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