2011-03-25 77 views
1

我正在为Chrome浏览器的工具栏工作,作为扩展的一部分。比方说,该工具栏是由下面的CSS描述一个简单的矩形:谷歌浏览器,html工具栏 - 始终处于顶级问题

#top{ 
    display: none; 
    width: 100%; 
    background: red; 
    z-index:9999999; 
    height:40px; 

} 

我注入看起来更不像工具栏:

<body> 
    <div id="panel_left"> 
    .... 
    </div> 
    <div id="panel_right"> 
    .... 
    </div> 
</body> 

而且我通过它注入到IFRAME

$("body").before('<iframe name="top" id="top" frameborder="0"></iframe>'); 
var top = document.getElementById("top"); 
top.src = chrome.extension.getURL("top.html"); 

问题出现在某些网页上,因为它们的CSS可以覆盖我的工具栏。我希望工具栏从网站最顶端开始,高度为40px,然后显示通常的网页内容。

你有任何想法如何做到这一点(或者说改进它,因为它适用于某些网页)

回答

0

只是为了寻找同样的解决方案的所有用户。它的工作原理:

body 
{ 
position: fixed; 
width: 100%; 
height: 100%; 
position:relative; 
} 
1

你有没有尝试添加:

top: 0; 
left: 0; 
margin: 0; 
padding: 0; 

之前添加此插入您工具栏:

// Take down the webPage 
document.getElementsByTagName('body')[0].style.marginTop = '39px'; 
// Or more if your toolbar is greater 
+0

请在看看:HTTP://www.emposha .com /这是网站的例子,工具栏仍然无法正常工作...如果你有任何想法如何解决它,将是伟大的! – dbq 2011-03-26 00:20:40

+0

我在这个网站上工作,你能提供一个什么样的屏幕? – Sindar 2011-03-26 15:06:42

+0

当然可以!我为您提供了emposha.com顶部的一个屏幕。红色矩形就是我的工具栏,所以你可以看看会发生什么: http://www.biqueter.com/fail.png – dbq 2011-03-26 18:48:03