2015-07-03 208 views
1

我有這樣的問題。我需要打開彈出窗口按下按鈕(這個動作被執行)。然後彈出窗口將被加載它應該被關閉。加載後關閉彈出窗口

$(document).ready(function() { 
    $('#popupButton').click(function() { 
     signinWin = popupwindow([url], 
       "SignIn",960,630); 
     signinWin.focus(); 
     signinWin.onload=function(){ 
      var code = getQueryVariable("code"); 
      if(code != null){ 
       signinWin.opener.location.reload(true); 
       signinWin.close(); 
      } 
     } 
    }); 
}); 

我該怎麼做才能關閉彈出窗口?原因signinWin.close();在onload事件

回答

1

不起作用嘗試在第三個參數設置windowheightwidth使用字符串"width=960,height=630"window.open();利用document.write關閉windowsigninWin

$(document).ready(function() { 
    $("#popupButton").click(function() { 
    var signinWin = window.open("/url/", "SignIn","width=960,height=630"); 
    signinWin.focus(); 
    var code = getQueryVariable("code"); 
    if (code != null) { 
     signinWin.document.write("<script>this.close()<\/script>"); 
     setTimeout(function() { 
      location.reload(true); 
     }, 1); 
    }; 
    }); 
}); 

的jsfiddle http://jsfiddle.net/scuxhbva/

+0

你不明白,功能popupwindow()打開新窗口。它使用window.open函數popupwindow(url,title,w,h)var left =(screen.width/2) - (w/2); \t var top =(screen.height/2) - (h/2); \t return window.open(url,title,'toolbar = no,location = no,directories = no,status = no,menubar = no,scrollbars = no,resizable = no,copyhistory = no,width ='+ w +' ,height ='+ h +',top ='+ top +',left ='+ left); '但是問題是我只需要在關閉窗口後才加載 –

+0

謝謝。這一行幫助我關閉了彈出窗口:signinWin.document.write(「