homepage Welcome to WebmasterWorld Guest from 54.196.194.204
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Hidden div not displaying in IE8
neha11




msg:4110641
 10:08 am on Apr 6, 2010 (gmt 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

 

daveVk




msg:4110724
 12:53 pm on Apr 6, 2010 (gmt 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 )

neha11




msg:4110743
 1:37 pm on Apr 6, 2010 (gmt 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

rocknbil




msg:4110908
 5:59 pm on Apr 6, 2010 (gmt 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.'); }
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved