Welcome to WebmasterWorld Guest from 23.20.18.183

Forum Moderators: incrediBILL

Message Too Old, No Replies

Hidden div not displaying in IE8

     
10:08 am on Apr 6, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 8, 2010
posts: 8
votes: 0


Hi
I have a hidden div in my web page. when the site is visited for the first time that div is displayed and simultaneously a cookie is set which is done as follows

<script type="text/JavaScript">
document.getElementById(''ISI_TopBox'').style.display = ''none'';
var v = checkCookie1();

if (v != null) {
document.getElementById(''ISI_TopBox'').style.display = ''none'';

}
else {
document.getElementById(''ISI_TopBox'').style.display = ''block'';
createCookie1("myname", "myvalue","1");
}
function checkCookie1() {
return (readCookie1(''myname''));
}
function readCookie1(name) {
var nameEQ = name + "=";
var ca = document.cookie.split('';'');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)=='' '') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function createCookie1(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires = "+ date.toGMTString();
}
else var expires = "";
document.cookie = name + "="+ value + expires + "; path=/"; // available throughout the directory
}
</script>


This cookie when set hides the div on next visit. This functionality is not working in IE8. The hidden div does not displays at all even after clearing cookies and temp files. what could be the problem. Please help
12:53 pm on Apr 6, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


document.getElementById(''ISI_TopBox'').style.display = ''none'';
var v = checkCookie1();
if (v != null) {
document.getElementById(''ISI_TopBox'').style.display = ''none'';
}
else {
document.getElementById(''ISI_TopBox'').style.display = ''block'';
createCookie1("myname", "myvalue","1");
}

This section of code need to be executed after the page is loaded ( when ISI_TopBox is known )
1:37 pm on Apr 6, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 8, 2010
posts:8
votes: 0


I have inserted this script after the ISI_
TopBox sectionand if this whole script is called on page load then the cookie checking takes time and for a fraction of second the hidden dicv displays and then disappears so have to insert the script alongwith the html part
5:59 pm on Apr 6, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


I don't understand the need or function of the doubled single quotes. (?)

Try changing just this part, then you can put it wherever you want, even as an external .js file.


window.onload=function() { initDivHider(); };
//
function initDivHider() {
if document.getElementById('ISI_TopBox')) {
document.getElementById('ISI_TopBox').style.display = 'none';
var v = checkCookie1();
if (v != null) {
document.getElementById('ISI_TopBox').style.display = 'none';
}
else {
document.getElementById('ISI_TopBox').style.display = 'block';
createCookie1("myname", "myvalue","1");
}
// This should never trigger - but if it does, it tells you ISI_TopBox
// canot be found, which could indicate a validation error breaking
// the Javascript.
else { alert('ISI_TopBox element cannot be accessed.'); }
}