2013年10月30日 星期三

iframe 子視窗呼叫母視窗函式並關閉視窗

母視窗
html
<iframe id="iframe01" src="/test/A/" height="450px" frameborder="0" width="100%">你的瀏覽器竟然不支援 iframe</iframe>

js
使用dialog開啟子視窗,因子視窗為上傳檔案故無使用ajax方式
$("#subMenu").dialog("open");
子視窗也是使用iframe
<iframe id="iframe02" src="/test/B/" height="300px" frameborder="0" width="100%">你的瀏覽器竟然不支援 iframe</iframe>

//關閉視窗 供子視窗呼叫使用
function closeUpLoadWindows() {
    $.growlUI('檔案資訊已更新!', '您辛苦了');
    $("#subMenu").dialog("close");
}

子視窗
$('#form1').submit(function () {
    return valid_form();
});

//驗證上傳欄位
function valid_form() {
    if ($("#Version").val() == "") {
        alert("請填入版本");
        return false;
    }
    else if ($("#file").val() == "") {
        alert("請選擇檔案!");
        return false;
    }
    else {
        //關閉視窗
        if (window.parent.document) {
            window.parent.closeUpLoadWindows(); //call 母視窗js
        }
    }
}



畫面


Visual Studio JS intellisense 失效解決方式

  試了好久,發現到工具>選項>IntelliCode js項目設定啟用,重新開啟VS就正常了! 後來發現是TypeScript3.2版有問題停用,使用4.3版的TypeScript即可