I have a hidden element that pops up after a certain amount of time.
However, if someone goes back to the website again, they have to wait the same amount of time as they did before for the hidden element to appear again.
I would like to integrate cookie tracking so that once the person returns to the website, the hidden element will still be there again rather than having to go through the same wait every time they return.
[B]This is the current script the head:
[CODE]<!– START PASTE HERE –>
<script type=”text/javascript”>
<!–
////////////////////////////////////////////
// CHANGE THE SECONDS DELAY BELOW TO //
// THE NUMBER OF SECONDS YOU WANT BEFORE //
// THE LINKS APPEAR //
////////////////////////////////////////////
$secondsdelay = 30;
////////////////////////////////////////////
// DO NOT EDIT THIS SECTION //
////////////////////////////////////////////
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
item.className=(item.className==’hidden’)?’unhidde n’:’hidden’;
}
}
$delay = $secondsdelay*1000;
window.setTimeout(“unhide(‘links’)”,$delay);
//–></script>
<STYLE TYPE=”text/css”>
.hidden { visibility: hidden; }
.unhidden { visibility: visible; }
</STYLE>
<!– END PASTE HERE –>
[B]here is the script in the body:
[CODE]<div id=”links” class=”hidden”><img class=”wp-image-26 aligncenter” src=”http://hiddenhealthquest.com/wp-content/uploads/2016/09/buybuybuy.png” alt=”buybuybuy” width=”361″ height=”348″ /></div>
how should I modify this for my purposes?
[code=html]<div id="links" class="hidden">[/code]
to [code=html]<div id="links">[/code]
and forget about having the javascript to unhide the links as it won't be required.[CODE] <div id="hidden-element">Your hidden element</div>
<script>
var lsAvailable;
var he = document.getElementById("hidden-element");
try {
localStorage.setItem("lsAvailable", "true");
localStorage.removeItem("lsAvailable");
lsAvailable = true;
} catch (e) {
lsAvailable = false;
}
if (lsAvailable) {
var visited = localStorage.getItem("visited")
if (!visited) {
he.style.display = "none";
window.setTim
<i>
</i>// try accessing it, if its not seen, set the time out for it
try{
var hasSeen = Number( localStorage.getItem("seen") );
}catch( e ){
localStorage.setItem("seen",30);
}
// if hasSeen has been seen, then it will be 0 otherwise it will be 30
setTimeout("unhide('links')", hasSeen*1000 );
// now change it.
localstorage.setItem("seen",0);
<!-- START PASTE HERE -->
<script type="text/javascript">
<!--
////////////////////////////////////////////
// CHANGE THE SECONDS DELAY BELOW TO //
// THE NUMBER OF SECONDS YOU WANT BEFORE //
// THE LINKS APPEAR //
////////////////////////////////////////////
$secondsdelay = 30;
////////////////////////////////////////////
// DO NOT EDIT THIS SECTION //
/////////////////////////////////////////
and also remove <i>
</i>$delay = $secondsdelay*1000;
[CODE] <div id="hidden-element">Your hidden element</div>
<script>
var lsAvailable;
var he = document.getElementById("hidden-element");
try {
localStorage.setItem("lsAvailable", "true");
localStorage.removeItem("lsAvailable");
lsAvailable = true;
} catch (e) {
lsAvailable = false;
}
if (lsAvailable) {
visited = localStorage.getItem("visited")
if (!visited) {
he.style.display = "none";
window.setTimeout(function () {
localStorage.setItem("visited", "true");
he.style.display = "block";
}, 5000)
}
}
</script>[/CODE]
<i>
</i>// the unhide function
function unhide(divID) {
if ( var item = document.getElementById(divID) ) {
item.className = (item.className=="hidden")? "unhidden" : "hidden";
}
}
// try accessing it, if its not seen, set the time out for it
try{
// try to get the item stored, it will be 1200 or 0 if its been set, then cast it to a number
var hasSeen = Number( localStorage.getItem("seen") );
}catch( e ){
/*
20 minutes = 1200 seconds this runs if the object has not been
set because it is the catch part of an error routine
*/
localStorage.setItem("seen",1200);
}
// if hasSeen has been seen, then it will be 0 otherwise it will be 1200
setTimeout("unhide('links')", hasSeen*1000 );
// now change it to 0 because the item will be seen on next visit
localstorage.setItem("seen",0);
JavaScript if disabled would result in your links never showing, thats somethign to consider because even today, special types of web browser have no javascript support, slthough they are small in number, they serve a small user group based on their needs, so if your site has links that the user can't see, then that limits your sites usability. [/QUOTE]
My previous posting was incomplete, here it is again:[CODE] <div id="hidden-element">Your hidden element</div>
<script>
var lsAvailable;
var he = document.getElementById("hidden-element");
try {
localStorage.setItem("lsAvailable", "true");
localStorage.removeItem("lsAvailable");
lsAvailable = true;
} catch (e) {
lsAvailable = false;
}
if (lsAvailable) {
visited = localStorage.getItem("visited")
if (!visited) {
he.style.display = "none";
window.setTimeout(function () {
localStorage.setItem("visited", "true");
he.style.display = "block";
}, 5000)
}
}
</script>[/CODE]
[/QUOTE]
[CODE]<div id="links" class="hidden"><img class="wp-image-26 aligncenter" src="http://hiddenhealthquest.com/wp-content/uploads/2016/09/buybuybuy.png" alt="buybuybuy" width="361" height="348" /></div>
<script>
var lsAvailable;
var he = document.getElementById("hidden");
try {
localStorage.setItem("lsAvailable", "true");
localStorage.removeItem("lsAvailable");
lsAvailable = true;
} catch (e) {
lsAvailable = false;
}
if (lsAvailable) {
visited = localStorage.getItem("visited")
if (!visited) {
he.style.display = "none";
window.setTimeout(function () {
localStorage.setItem("visited", "true");
he.style.display = "block";
}, 5000)
}
}
</script>[/CODE]
[CODE]<div id="links" class="hidden"><img class="wp-image-26 aligncenter" src="http://hiddenhealthquest.com/wp-content/uploads/2016/09/buybuybuy.png" alt="buybuybuy" width="361" height="348" /></div>
<script>
var lsAvailable;
var he = document.getElementById("hidden");[/CODE]
[/QUOTE]
Your div has the [B]class[/B] "hidden" but getElementById() get's the element by it's [B]ID[/B] which is "links".[CODE]var he = document.getElementById("links");[/CODE]
[CODE]<div id="links" class="hidden"><img class="wp-image-26 aligncenter" src="http://hiddenhealthquest.com/wp-content/uploads/2016/09/buybuybuy.png" alt="buybuybuy" width="361" height="348" /></div>
<script>
var lsAvailable;
var he = document.getElementById("links");
try {
localStorage.setItem("lsAvailable", "true");
localStorage.removeItem("lsAvailable");
lsAvailable = true;
} catch (e) {
lsAvailable = false;
}
if (lsAvailable) {
visited = localStorage.getItem("visited")
if (!visited) {
he.style.display = "none";
window.setTimeout(function () {
localStorage.setItem("visited", "true");
he.style.display = "block";
}, 5000)
}
}
</script>[/CODE]
is there something comeing from my site into localstorage on your browser?[/QUOTE]Yes, my browser stores the item "visited".
standard practice
standard practice
[CODE]<script type="text/javascript">
<!--
////////////////////////////////////////////
// CHANGE THE SECONDS DELAY BELOW TO //
// THE NUMBER OF SECONDS YOU WANT BEFORE //
// THE LINKS APPEAR //
////////////////////////////////////////////
$secondsdelay = 30;
////////////////////////////////////////////
// DO NOT EDIT THIS SECTION //
////////////////////////////////////////////
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
item.className=(item.className=='hidden')?'unhidde n':'hidden';
}
}
$delay = $secondsdelay*1000;
window.setTimeout("unhide('links')",$delay);
//--></script>
<STYLE TYPE="text/css">
.hidden { visibility: hidden; }
.unhidden { visibility: visible; }
</STYLE>
[/CODE]
typo = typographical error, meaning you mistyped something, missed something out or additional letters / characters or wrong spellings.
as pointed out, you do not need [b]type="text/javascript"[/b]
As for being messed with, it is very doubtful.[/QUOTE]
as pointed out, you do not need type="text/javascript"[/QUOTE]
Line 157, Column 11: required attribute "type" not specified
<p><script>
✉
The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.
Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.[/QUOTE]
[CODE]<!-- START PASTE HERE -->
<script type="text/javascript">
<!--
////////////////////////////////////////////
// CHANGE THE SECONDS DELAY BELOW TO //
// THE NUMBER OF SECONDS YOU WANT BEFORE //
// THE LINKS APPEAR //
////////////////////////////////////////////
$secondsdelay = 30;
////////////////////////////////////////////
// DO NOT EDIT THIS SECTION //
////////////////////////////////////////////
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
item.className=(item.className=='hidden')?'unhidde n':'hidden';
}
}
$delay = $secondsdelay*1000;
window.setTimeout("unhide('links')",$delay);
//--></script>
<STYLE TYPE="text/css">
.hidden { visibility: hidden; }
.unhidden { visibility: visible; }
</STYLE>
<!-- END PASTE HERE -->[/CODE]
Additionally I had to make the container visible be disabling this in style.css:[CODE]/*.hidden
{
display: none;
}*/[/CODE]
by deleting the script i will have nothing in the head[/QUOTE]?? There is much more in the head. Delete only the code I posted.
and by disable you mean delete that part?[/QUOTE]Yes, delete it or make it a remark as I posted.
0.1.9 — BETA 5.20