2012-03-09 118 views
-2

onclick函數無法正常工作,因爲即使在關閉父窗口後仍會禁用所有鏈接。 在關閉彈出窗口時,父頁面鏈接不再工作。其他一切工作正常。彈出窗口無法正常工作

我的代碼是: -

   function MyPopUpWin(message) { 
      var iMyWidth; 
     var iMyHeight; 
     //half the screen width minus half the new window width (plus 5 pixel borders). 
      iMyWidth = (window.screen.width/2) - (75 + 10); 
     //half the screen height minus half the new window height (plus title and status bars). 
      iMyHeight = (window.screen.height/2) - (100 + 50); 
     //Open the window. 
var generator = window.open(); 
document.onclick=function() { 
    try{ 
     generator.focus(); 
     return false 
    } 
    catch(e){} 
} 

generator.document.write('<html><head><title>Pop uP</title>'); 
generator.document.write('<p style="color:#C52B27;">'); 
generator.document.write(message); 
generator.document.write('</p>'); 
generator.document.write('</head><body>'); 

generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0"> <\/a>'); 
generator.document.write('</body></html>'); 
generator.document.close(); 
} 

回答

1

關閉窗口後,對它的引用不丟失......而.focus()方法不會失敗。所以你try/catch沒有做什麼你認爲..

<a href="javascript:window.opener.document.onclick = null;self.close();"> 
+0

.....感謝的人,它工作正常....但可以dere是一些其他的解決方案。最後,我做了一個彈出的問題,並提出這個解決方案,我的問題http://stackoverflow.com/questions/ 9376102 /如何禁用父窗口,而孩子窗口出現點擊按鈕上的參數.....但這次焦點代碼不工作在我的功能 – rcky 2012-03-09 11:55:55

1

你有彈出窗口關閉後從document刪除onclick -eventhandler。

編輯:

我不知道這可能是比蓋比的回答甚至更好,但試試這個:

document.body.onfocus=function(){generator.focus();return false;} 

,然後廢掉onfocus退出彈出窗口時。

或者只是在父窗口上使用(部分?)透明蓋div,而彈出窗口是打開的。

第二版

,甚至使用showModaDialog()爲你彈出,雖然這個解決方案需要的其他文件,加載模態對話框。

+0

@Teemu。 ......感謝你的建議......你能否提出一些其他的解決方案 – rcky 2012-03-09 11:59:29

+0

@rcky你的意思是,這個鏈接應該在父文檔中處於活動狀態,而彈出窗口是打開的? – Teemu 2012-03-09 12:02:50

+0

不.....我希望當彈出打開父頁面鏈接應該禁用和關閉它,鏈接應該是積極的,但通過一些更好的方法 – rcky 2012-03-09 12:05:22