2016年7月21日 星期四

Windos.open傳值問題

重點注意:若chrome不能執行,請用IE

方法一:單純傳值法

母:
  1. function openWindow(){
  2. window.open('upload.html','mywindow','width=400,height=200');
  3. }

子:
  1. function backToParent(){
  2. //opener(母視窗)的form1的輸入值 = 目前網頁(子視窗)form2輸入的值
  3. opener.document.form1.textInput.value = document.form2.input.value;
  4. window.close();
  5. }


方法二:呼叫母視窗的某個方法,並帶參數

母:
  1. function action4(){
  2. window.open('popupView.html','PopupView', config='height=350,width=350');
  3. //document.getElementById("myText").value = window.returnValue;
  4. }
  5.  
  6. function actionFather(Value){
  7. //alert("Value")
  8. var Value = Value;
  9. }


子:

  1. function action5(){
  2. window.opener.actionFather("haha"); //呼叫父視窗的actionFather方法,並把值傳過去給他
  3. window.close();
  4. }

沒有留言:

張貼留言