主要想实现的效果是:
主页面需要点击“地址薄”,弹出地址薄选择页面,然后选择完地址,又回到主页面并插入了所选的地址。
主页面需要写的javascript类似于:
[javascript]
<script language=”javascript”>
function AddressWindow()
{
try {
var url= “/pages/addressbook/selectaddressbook.faces”;
var AWnd=window.open(url,”地址簿”,”width=620,height=600,top=100,left=100, location=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes”);
if ((document.forms[0].window != null) && (!AWnd.opener)) AWnd.opener = document.forms[0].window;
AWnd.focus();
} catch(e) {
show_exception(e);
}
}
</script>
[/javascript]
地址薄选择页面需要写的javascript类似于:
[javascript]
<script language=”javascript”>
var openerid = “addressbookForm”;
var addresss = window.opener.document.getElementById(openerid+”:addresslist”).value;
function selectAll(formid,inode) {
var tableNode = document.getElementById(formid+”:addressbookClassItem”);
var tableNode2 = document.getElementById(formid+”:addressbookItem”);
var il = tableNode.getElementsByTagName(“input”);
var il2 = tableNode2.getElementsByTagName(“input”);
if(inode.checked) {
for(var i=0;i<il.length;i++) {
if(il[i].type == ‘checkbox’) {
il[i].checked = true;
}
}
for(var i=0;i<il2.length;i++) {
if(il2[i].type == ‘checkbox’) {
il2[i].checked = true;
}
}
}else {
for(var i=0;i<il.length;i++) {
if(il[i].type == ‘checkbox’) {
il[i].checked = false;
}
}
for(var i=0;i<il2.length;i++) {
if(il2[i].type == ‘checkbox’) {
il2[i].checked = false;
}
}
}
}
function selectClass(formid,inode) {
var classid = inode.parentNode.getElementsByTagName(“input”)[1].value;
var tableNode = document.getElementById(formid+”:addressbookItem”);
var il = tableNode.getElementsByTagName(“input”);
if(inode.checked) {
for(var i=0;i<il.length;i+=3) {
if(il[i+2].value == classid) {
il[i].checked = true;
}
}
}else {
for(var i=0;i<il.length;i+=3) {
if(il[i+2].value == classid) {
il[i].checked = false;
}
}
}
}
function fill_address(formid)
{
var tableNode = document.getElementById(formid+”:addressbookItem”);
var il = tableNode.getElementsByTagName(“input”);
for(var i=0;i<il.length;i++) {
if(il[i].checked) {
var email = il[i].parentNode.getElementsByTagName(“input”)[1].value;
addresss = addresss + email + “,”;
}
}
window.opener.document.getElementById(openerid+”:addresslist”).value = addresss;
window.close();
}
</script>
[/javascript]