关于浏览器JS弹出框警告

JavaScript09

关于浏览器JS弹出框警告,第1张

这个和你浏览器安全设置有关,浏览器会默认拦截弹出框。不知道你用的是那种形式,是window.open()还是window.showModalDialog()、window.showModelessDialog()。前面的方式是弹出窗体,后面的两种是弹出模式窗体,后两种被拦截的几率较小。以弹出层的形式会更好、这样可以兼容多个浏览器。

常用两种返回方法:

1.window.showModalDialog(url,args,dialogattrs) 

参数说明: 

url:弹出页面地址 

agrs:主窗口传给对话框的参数,可以是任意类型(数组也可以) 

dialogattrs:弹出窗口的样式参数 

模式对话框用法: 

主窗口:var value =window.showModalDialog('test.jsp',strs,'resizable:yes') 

弹出框中通过window.returnValue设置返回值。

2。window.open: 

【父窗口】 

代码如下: 

<script> 

function show_child() 

var child=window .open("child.html","child","height=200,width=400,status=yes,toolbar=no,menubar=no,location=no") 

/* if(!child.closed) 

if(!window .close()) 

var textValue = frm.txt.value parent.frm0.txt0.value = textValue 

else 

window .close() 

child.close() 

}*/ 

</script> 

<a href="javascript:show_child()">打开子窗口</a> 

<form name=frm0> 

<input type="text" name="txt0" id="txt0"> //注意这里一定要写ID属性不然FF下取不到值 

</form> 

【子窗口】

代码如下: 

<script> 

function choseItem() 

var v="" 

var check_item = document.frm.item 

for(i=0i<check_item.lengthi++) 

if(check_item[i].checked) 

v+=","+check_item[i].value 

document.frm.txt.value=v.replace(/^,{1}/,"") 

function foo() 

window .close() 

window .opener.document.getElementById("txt0").value=document.getElementById("txt").value 

</script> 

<body> 

<form name=frm> 

<input type=checkbox name=item value=1 onclick="choseItem()">a 

<input type=checkbox name=item value=2 onclick="choseItem()">b 

<input type=checkbox name=item value=3 onclick="choseItem()">c 

<input type=checkbox name=item value=4 onclick="choseItem()">d 

<input type=text name="txt" id="txt"> 

</form> 

<input type=button value="关闭" onclick="foo()"> 

</body>

<input type="button" value="点我" onclick="clickMe()"/>

<script>

function clickMe() {

if (confirm("确定或取消")) {

alert("你点的确定")

} else {

alert("你点的取消")

}

}

随便写了两句,目测没问题,有问题百度

</script>

你补充的内容建议你用easyui或者jQueryUI做比较简单,单纯的js好像有点复杂