// 開啟模態視窗 (單選)
function showModalOnly(hiddenId, url) {
var hidden = document.getElementById(hiddenId);
if (hidden?.value) return alert('單選模式,請先刪除既有選項');
var ret = window.showModalDialog(url, window,
'dialogHeight:500px;dialogWidth:987px;status:off;scroll:auto');
if (!ret) return;
var [hidPart, viewPart] = ret.split('^');
var hids = hidPart.split('&'), views = viewPart.split('&');
if (hids.length !== 2) return alert('請只選擇一條資料');
hidden.value = hids[0];
document.getElementById('check' + hiddenId).innerHTML +=
`

${views[1]}
`;
}
// 通用開啟模態視窗
function openUploadWindow(url, w=987, h=500, l=200, t=200) {
window.showModalDialog(url, window,
`dialogHeight:${h}px;dialogWidth:${w}px;status:off;scroll:auto;dialogLeft:${l}px;dialogTop:${t}px`);
}
function returnParent(value) {
var parent = window.dialogArguments;
if (parent) {
window.returnValue = value;
window.close();
}
}
// 呼叫範例:returnParent('id123^顯示文字');
// 父頁面
var win = window.open(url, '_blank', 'width=987,height=500');
window.addEventListener('message', function (e) {
if (e.origin !== location.origin) return;
console.log('子頁面傳回:', e.data);
});
// 子頁面
window.opener.postMessage({ id: '123', name: '測試' }, location.origin);
window.close();
⚠️ showModalDialog 已從標準移除,Chrome 43+、Firefox、Edge 均不支援,新專案請改用 postMessage + window.open。