简体   繁体   English

Internet Explorer javascript style.height无法正常工作

[英]internet explorer javascript style.height not working

I am trying to create a cookie policy alert for a website, just something simple like a bar at the top of the screen. 我正在尝试为网站创建Cookie策略警报,就像在屏幕顶部的栏一样简单。 The idea is that the user has to click close before the bar will disappear. 这个想法是用户必须在栏消失之前单击关闭。 The concept works fine in google chrome however in internet explorer 9, it does not alter its height when clicked. 该概念在谷歌浏览器中可以正常工作,但是在Internet Explorer 9中,单击时不会改变其高度。

Here is my code (I know it is basic but unfortunately it has to be due to the platform the establishment uses- 这是我的代码(我知道这是基本代码,但不幸的是,这必须归功于企业使用的平台-

<script language=javascript type='text/javascript'> 
function hideDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideShow').style.height= '0px'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideShow.height= '0px'; 
} 
else { // IE 4 
document.all.hideShow.style.height= '0px'; 
} 
} 
} 

function showDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideShow').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideShow.visibility = 'visible'; 
} 
else { // IE 4 
document.all.hideShow.style.visibility = 'visible'; 
} 
} 
} 
</script> 

<style>
#hideShow{
color:white;
font-family:Gill Sans MT;
text-align:center;
font-height:20px;
</style>

<div id="hideShow" ..etc> 
My content 
<a href="javascript:hideDiv()">Close</a> 
</div> 

Also, if anyone would be so kind, could you please explain how I could set it up so that the div 'hideShow' shows up until it is clicked, and then never again on that machine? 另外,如果有人那么善良,请您解释一下我如何进行设置,以便div'hideShow'一直显示到被单击为止,然后再也不会在该计算机上显示?

Please let me know if you need any more details. 如果您需要更多详细信息,请告诉我。 Thanks in advance Rob 在此先感谢Rob

The issue was that the height had to be defined within the hideShow css. 问题是必须在hideShow CSS中定义高度。 As well as the font size. 以及字体大小。 Then the javascript had to set height and fontSize to 0px. 然后,JavaScript必须将height和fontSize设置为0px。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM