Forum Moderators: open
the site is set up so that the #content div is in a layer above the #menu div. I have been able to hide the content div to view the menu, which is fine once you are navigating the site, but for the initial page load, i just want the #menu div visible.
any help would be great.
Thanks,
Aaron
Make the CSS so that the upper layer initially cover the menu. Then it will cover it on the first page load. Then set the cookie. It will be set on the 2nd and consequent loads. Test for it and if it's present, set the layer's style.visibility to "hidden" to show the menu.
[edited by: Otaku at 2:21 pm (utc) on May 5, 2008]
<script type="text/javascript">
function checkCookie() {
//establish DIV object to manipulate
contentDiv=document.getElementById("content");
//check if cookie includes "mycookie"
if (document.cookie.indexOf("mycookie")!=-1) {
//if it does (not false), display the DIV object
contentDiv.style.display="block";
}
else {
//if it does not, set the cookie for next page load
document.cookie="mycookie=1";
}
}
</script>
<body>
<!-- Here's the "content" DIV element
It doesn't display until the cookie is set -->
<div id="content" style="display:none">Content here..</div>
<!-- Here's the "menu" DIV element -->
<div id="menu" style="display:block">Menu here...</div>
<script type="text/javascript">
//check for the cookie and display DIV or set cookie
checkCookie();
</script>
</body> There are tons of Javascript references on the web, and almost all of them include cookie syntax and useage. Good luck!
<edit: added comments>
[edited by: StupidScript at 9:26 pm (utc) on May 6, 2008]
I was just trying something else. When I'm adding the content via the backend, I should be able to ad a piece of JS (a var maybe?) in with the text, and then when the browser renders the page, a function on the main index.php can check whether the var is in the content and display/hide the div accordingly? that should work shouldn't it?
index.php head
function checkVar() {
var dsiplayContent=new Boolean()
//establish DIV object to manipulate
contentDiv=document.getElementById("content");
//check if page includes "mycookie"
if (dsiplayContent == true) {
//if it does (not false), display the DIV object
contentDiv.style.visibility="visible";
}
else {
//if it does not, set the cookie for next page load
contentDiv.style.visibility="hidden";
}
}
content via editor
<script type="text/javascript">
dsiplayContent = true
</script>
<script type="text/javascript"><!--
showMenu();
--></script>
To make it real, we need to have the content DIV to be initially visible, and also insert the following code at the header of every page:
<script type="text/javascript"><!--
function showMenu()
{
document.getElementById( "content" ).style.visibility = "hidden";
}
--></script>