2011-08-24 17 views
2

我使用window.open()打開window.open出現在webkit瀏覽器後面,但是如果我打開Facebook或Twitter頁面,則不會。

http://twitter.com/share ..和 http://www.facebook.com/sharer.php ...

,允許用戶發佈自己的Facebook或Twitter帳戶。

這些彈出窗口正確顯示在我當前的Chrome或Safari窗口的正面。

但是,當我將URL更改爲當前域中的另一個頁面時,彈出窗口顯示在當前窗口的後面,而不是infront!?相同的代碼,打開窗口的相同函數,只是傳遞給window.open()的一個不同的URL。

我弄不明白爲什麼,我試過了一切,在彈出的頁面中註釋掉任何javascript或任何可能導致Chrome/Safari認爲它是惡意的。

這些瀏覽器是否將URL檢測爲Facebook/Twitter並允許它出現在前面,並將其他東西推到後面?

這是我打開窗戶

InfoOverlay.prototype.popupWindow = function(url, title, width, height) 
{ 
    var left = (screen.width/2) - (width/2); 
    var top = (screen.height/2) - (height/2); 
    var targetWin = window.open(
     url, 
     title, 
     'toolbar=no, location=no, directories=no, alwaysRaised=yes, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left 
    ); 

    // These 2 lines added on suggestion from commenter below 
    // (doesn't fix issue) 
    targetWin.blur(); 
    targetWin.focus(); 
} 
+0

使用'window.foucs()' – anu

回答

1

這可能是你所如雨後春筍般冒出打開的網頁在他們的代碼專注自己的功能(例如window.focus()的;)

你應該可以在打開窗口的頁面中的代碼中執行該操作,只需確保給窗口一個名稱,然後執行WindowName.focus();

在HTML這種快速樣機似乎IE9,Chrome瀏覽器,FF4工作,但不是Safari瀏覽器(在Windows 3.x的我)

<script> 
var myWin 
</script> 
<button onclick="myWin = window.open('about:blank', 'foo', 'height=200,width=200,modal=yes,alwaysRaised=yes');">Show Window</button> 
<button onclick="myWin.blur();">Blur</button> 
<button onclick="myWin.focus();">Focus</button> 
+0

揭掉試圖最初,沒有快樂。爲了安全起見,我在某個地方讀了一些他們阻止.focus()的地方。 – Titan

+0

回覆您的編輯我已將原始文章中的代碼放入代碼中,向您展示我的代碼仍未將其展示給前臺(但傳遞給它的Twitter和Facebook網址沒有任何問題)。 – Titan

相關問題