There is a site with a block layout. Blocks: header, navigation, content, menu, footer. There is a navigation bar with buttons (navigation). When you click on the button information is loaded into the content block.

How to make it so that after logging in to the site, the Login button changes to the Exit button. Only jacascript is available, which I do not know.

As I think, it is necessary to check js with the user’s cookies, and if there is no navigation block (Home, account, website, Logout), and if it has expired, then navigation2 block (Home, account, website, Log in) .

I set the blocks as:

<div id="navigation" style="display:none"> <div id="navigation1" style="display:none"> 

css:

 #navigation { display: block; background: #a2a2a2; width: 900px; height: 40px; } #navigation1 { display: block; background: #a2a2a2; width: 900px; height: 40px; } 

js:

 function getCookie(name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset) if (end == -1) { end = cookie.length; } setStr = unescape(cookie.substring(offset, end)); } } return(setStr); } myVar = getCookie("la2user"); if (myVar !== null) {document.getElementById('navigation1').style.display = 'block'; } else {document.getElementById('navigation').style.display = 'block'; } 

I try so. It does not work, although if after writing {alert(myVar)} then the cookie displays.

  • As I think, it is necessary to check the js tool if the user has not expired cookies, so check if you have such an authorization system on your site. It all depends on how it is implemented (this system). If it is in cookies, read how to work with cookies and do it, if something does not come out of it or does not work, put it here, here it will help. - Moonvvell
  • I have another authorization system. using cgi, or rather python, I set cookies if all checks are performed. - Sergey White
  • Only the server knows about authorization. And he is not obliged to inform the client. If he reports, then indicate in the question how he does it. - D-side

1 answer 1

In the first question, do you need one block to be in another?

 <div id="navigation" style="display:none"> <div id="navigation1" style="display:none"> 

If not then close the tags -

 <div id="navigation" style="display:none"></div> <div id="navigation1" style="display:none"></div> 

Then there will be no problems. You just now have the second block in the first one, and if the first one is hidden, then the second one will be hidden regardless of the properties.

  • they are closed. I just dropped the blocks where the menu is closed. <div id="navigation" style="display:none"> <a href="http://мойсайт.ru" class="button" style="display:none">ГЛАВНАЯ</a> ... < / div> - Sergey White
  • jsfiddle.net/gpLk99w8 if closed then everything works as it should. In general, it is better to immediately generate an html page, depending on whether authorization has passed or not, with the block you need. - Moonvvell
  • closed but not working. It feels like {document.getElementById('navigation1').style.display = 'block'; } {document.getElementById('navigation1').style.display = 'block'; } just doesn't work - Sergey White
  • To the code that you have given in the question I wrote - close the tags and everything works, there is an example on the fiddle. In that example, you can change not equal to equal in the condition, and you will see that another block will show. Then give your specific code in which you want to change. - Moonvvell
  • Yes. looked fidl .. there works. my menu just disappears. I am puzzled .. now I will try to load everything into fidl - Sergey White