2012-09-28 39 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

相关问题