[ js ] window.open母視窗如何執行子視窗函式?
試做了一個Demo
http://tinyurl.com/38awpzf
母視窗:test1.html
子視窗:test2.html
點了母視窗頁面上的按鈕後,用window.open開了子視窗
有正確把值傳給了子視窗面裡的textarea
但如果要由母視窗傳變數到子視窗的變數
或是由母視窗執行子視窗的函式該如何做呢?
PassForm: 視窗名稱
Agrs : 變數
PassForm.document.getElementById("Text1").value = Agrs;
//正確可行
PassForm.document.testValue = Agrs;
PassForm.document.testFunction();
//這兩項好像都失敗了
完整JS如下
母視窗:
var TestCount = 0;
var Form;
function PassValueToForm(PassForm, Agrs) {
if ( PassForm.document.getElementById("Text1")) {
PassForm.document.getElementById("Text1").value = Agrs;
PassForm.document.testValue = Agrs;
PassForm.document.testFunction();
} else {
if (TestCount <= 10) {
setTimeout(function() { PassValueToForm(InForm, Agrs); }, 1000);
} else {
alert("失敗");
}
}
}
//按鈕事件:
function Button2_onclick() {
TestCount = 0;
Form = window.open("test2.html",name,'height=300,width=500');
setTimeout(function() {
PassValueToForm(Form, 'toTest2Value');
}, 1000);
}
子視窗:
var testValue = '20110102'; //測試用的變數,也是希望被改變的變數
//兩個測試的Function
function testFunction(){
alert("test2 Say Hi");
}
function testFunction2(){
alert(testValue);
}
查了一陣子,不太清楚方向...
不知道是不能這樣執行
或是要用其他方法?(例如cookie)
麻煩了...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.165.26
※ 編輯: Angelliya 來自: 114.32.165.26 (01/02 08:27)
※ 編輯: Angelliya 來自: 114.32.165.26 (01/02 08:27)
→
01/02 10:36, , 1F
01/02 10:36, 1F
→
01/02 10:37, , 2F
01/02 10:37, 2F
→
01/02 10:38, , 3F
01/02 10:38, 3F
→
01/02 10:39, , 4F
01/02 10:39, 4F
→
01/02 10:52, , 5F
01/02 10:52, 5F
→
01/02 14:29, , 6F
01/02 14:29, 6F