2013-04-04 136 views
2

當我調用window.open時,會刷新父窗口。我還沒有看到如何防止這種情況發生。任何幫助,將不勝感激。防止刷新父窗口中的window.open

left = Number((screen.width/2)-(730/2)), 
top = Number((screen.height/2)-(450/2)); 

var windowFeatures = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top='+top+',left='+left; 
    window.open('access-modal.html', '', windowFeatures); 

win.moveTo(left, top); 
+1

你是怎麼稱呼它的?您可能不會阻止默認操作。什麼是勝利? – epascarello 2013-04-04 18:53:42

+1

你確定你沒有把報價搞亂,因爲它不應該在window.open上刷新父項。 – adeneo 2013-04-04 18:53:46

+0

你缺少'window.open('access-modal.html','',windowFeatures)中的引號;' – 2013-04-04 18:55:50

回答

2

雖然編輯後我的文章有問題。最終的解決方案是防止默認操作。

$('.button').on('click', function(e) { 

    e.preventDefault(); 

     left = Number((screen.width/2)-(730/2)), 
     top = Number((screen.height/2)-(450/2)); 

     var windowFeatures = 'channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top='+top+',left='+left; 
      win = window.open('access-modal.html?env=' + Data.currentOauth + '&url=' + Data.currentAddr, '', windowFeatures); 

     win.moveTo(left, top); 
     win.focus(); 

    } 

}); 
+0

啊,你沒有說你在用jQuery。現在更有意義。我想知道爲什麼你不使用jQuery和jQuery-ui,但是在我看來,這不是一個有效的答案,告訴你應該使用你沒有要求的東西。 – 2013-04-04 21:01:27

1

我不知道它是否是您的編輯或不..我知道win.moveTo(左,頂部)有一個錯誤。 win沒有定義..下面的代碼是爲我工作的。

<script language="javascript" type="text/javascript"> 
      function windowOpen() { 
       left = Number((screen.width/2) - (730/2)), 
       top = Number((screen.height/2) - (450/2)); 

       var windowFeatures = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top=' + top + ',left=' + left; 
       var win = window.open('access-model.htm', '', windowFeatures); 

       win.moveTo(left, top); 
      } 
     </script>