2012-09-28 46 views
1

我有下面的代碼來打開一個彈出窗口,它工作正常。彈出窗口在彈出窗口中的代碼的主體標籤內具有黑色背景。bgcolor屬性可以傳遞給彈出窗口嗎?

當彈出窗口最初打開時,頁面有白色背景,然後代碼加載後變黑。這並不妨礙我,但它確實影響了我的客戶!

那麼,有沒有一種方法可以將顏色屬性bgcolor從父頁面上的javascript彈出,以便彈出窗口在打開時立即變爲黑色。我希望這是有道理的!

這裏是我當前的代碼:

// START OF POP UP /////////////////////////////////////////////////// 

function PopupCenter(pageURL, title,w,h) { 
    var left = (screen.width/2)-(w/2); 
    var top = (screen.height/2)-(h/2); 
    var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 
} 

// END OF POP UP /////////////////////////////////////////////////// 

<a href="javascript:void(0);" onClick="PopupCenter('page.asp', 'myPop1',678,550);" class="staffBioLinks">Click Here</a> 

回答

2

是。通過使用這樣的事情:

<script type="text/javascript"> 
function PopupCenter(pageURL, title,w,h) { 
    var left = (screen.width/2)-(w/2); 
    var top = (screen.height/2)-(h/2); 
    var targetWin = window.open ('about:blank', title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 
    targetWin.document.body.style.backgroundColor='#000'; 
    targetWin.location.href=pageURL; 
} 
</script> 

您打開一個空白頁,那麼你首先設置背景顏色,然後重定向到要加載的URL。在加載期間,頁面是黑色的(在我的例子中)。

+0

輝煌!工作完美,謝謝! – user1707446

+0

我在IE 9和Safari 5.1.4上試過了,它工作得很好。 – rationalboss

+0

好吧,只是發現我仍然在IE中得到了一個白色的閃光。還有什麼可以做的解決這個在IE瀏覽器?我的編程知識非常有限,但我猜想沒有!提前致謝。 – user1707446

0

您可以這樣做作爲查詢字符串。如果您可以獲取該值,那麼它應該像將它附加到頁面URL的末尾一樣簡單。

page.asppage.asp?bgColor=xxxxxx

您可以處理上卻彈出你想要對方的響應。

0

你可以做這樣的:

targetWin.document.bgColor = 'lightgreen'; 
targetWin.focus(); 
+0

這個工作也很完美,謝謝! – user1707446

相關問題