javascript is not my strong point so any assistance or help in the right direction would be much appreciated!
Basically I have a div which is hidden on my page which gets revealed to a user only if they are a new visitor according to the cookie set however it seems to all function well in firefox and chrome but using IE when clicking on the close button the page jumps back to the top and shows the hidden div (which is shouldnt, it should stay hidden)
HTML
<div id="theLink">
<?php if($this->countModules('tekenin2')) : ?>
<div id="gototop">
<div id="popup"><a href="#" onclick="parentNode.remove();return false; "><img src="/templates/marktoe/images/close.png" id="close" class="close" border="0" alt="close" /></a>
<jdoc:include type="modules" name="tekenin2" style="xhtml" />
</div>
</div>
<?php endif; ?>
Script 1
function createCookie(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=/";
}
function readCookie(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 eraseCookie(name) {
createCookie(name, "", -1);
}
function setTheDivStyle() { // body on load event
if (!readCookie('visited')) {
// if cookie not found display the div and create the cookie
document.getElementById("theLink").style.display = "block";
createCookie('visited', 'visited', 1); // 1 day = 24 hours persistence
} else {
// if cookie found hide the div
document.getElementById("theLink").style.display = "none";
}
}
Script 2 - where I suspect the problem is lying but I can be sure
window.addEvent('domready',function() {
/* smooth */
new SmoothScroll({duration:500});
/* link management */
$('theLink').set('opacity','0').setStyle('display','block');
/* scrollspy instance */
var ss = new ScrollSpy({
min: 10,
onEnter: function(position,enters) {
//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
$('theLink').fade('in');
},
onLeave: function(position,leaves) {
//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
//value below was #gototop div
$('theLink').fade('out');
},
onTick: function(position,state,enters,leaves) {
//if(console) { console.log('Tick [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
},
container: window
});
});
What I need is the div to be hidden, using the cookie check if the user is a new or returning one, if new show the div else hide it.
Any tips or suggestions would be greatly appreciated, like I said this is not my forte and I feel I am missing something fundamental. Ive browsed multiple other threads trying to wrap my head around it but to no avail. Thanks in advance!