主要想實(shí)現(xiàn)的效果是:

主頁面需要點(diǎn)擊“地址薄”,彈出地址薄選擇頁面,然后選擇完地址,又回到主頁面并插入了所選的地址。

主頁面需要寫的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類似于:

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