Hide div, display only at home

Asked

Viewed 522 times

3

How do I make to hide/remove the slider and banner underneath it with Javascript? I need him to stay at home only, but he’s repeating in every department website.

  • Good afternoon @Ucas, the best way to do is to check the code and restrict directly there, using javascript will be "solving" your problem but only visually. I advise checking the code structure.

  • 6

    It is much wiser to do the opposite. PUT div only at home. Anything else is gambiarra.

  • 1

    Ta using some kind of framework? wordpress or cakephp type or some kind of shop ready? You’d better specify more about your problem so we can help... do something in javascript to camouflage something you don’t want to show other than being a very ugly gambiarra only worsens the performance of your site as it can also bring you future maintenance problems

  • 1

    Please post the relevant code snippet here. Not only might the link not be on the air in the future, it will probably no longer display the problem you describe. And the ideal here is that the questions and answers also help future visitors with similar problems, not just who asked. Thank you.

  • We use the Ecommerce Ciashop platform. It only allows us to change the header and footer.

  • @Lucas can change the header and footer of each page or only all at the same time?

  • @Sergio, all at once.

Show 2 more comments

3 answers

2

You can search for text in the URL that identifies that you have changed page using the method index on the property Document.URL.

// Se encontrar o texto "/Departamento?idExpandido=" na URL 
// (creio que seja o suficiente para identificar que não é mais a homepage)
if (document.URL.indexOf("/Departamento?idExpandido=") > -1) { 
    // esconde os botões
    $(".carousel-indicators").hide(); 
    // Mais comandos
    // ...
}
  • 4

    It would be interesting to say what your code does and where it helps solve the problem, even if the explanation is obvious today, it might help several other developers

  • Thanks for the tip!

2

This type of client-side re-design (via Javascript) is not a good solution. It is best to be able to change this on the server side.

Assuming that’s not possible, then you need to find something to distinguish the pages. I noticed that the background menu does not work, this could be a help if it was working...

So the idea I had was to look for that text that shows which page you are on, and not on the front page.

The text is Início > Camisas > Manga 7/8
A dial for it would be: $('a[title="Início"]')

The idea is to have this code that, in case there is no such information, hides the slider.

if (!$('a[title="Início"]')) $('.imgBaFu').remove();

0

Two solutions to make the banner disappear when you click the menu.

Solution number 1:

$('#cssmenu').click(function(){
    $('.imgBaFu').hide();
});

Solution number 2:

(function($){
    $.getUrlVar = function(key){
    var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
    return result && unescape(result[1]) || "";
    };
})(jQuery);

var r = $.getUrlVar("idExpandido");

r != "" ? $('.imgBaFu').hide() : 0;

Running this on ready will solve your problem, already tested with Firebug on your site.

  • Maison, actually I wanted the banner (slider) and the banner below to appear only on the Home. In case, it appears on all pages of the site.

  • @Caputo I am providing the answer yes, I am giving the solution he asked, cover the banner when the page is not at home, that’s what he wants, that’s what I understood. In the second proposal I check if there is any value in the parameter passed via url, if there is no parameter is home, then it gives the Hide() in the banner

  • 2

    Hello @Maisonsakamoto the way it was before editing was treating only when there was a click. Your 2 yes solution works without the click and so can be an answer to Hide div, display only at home. I will remove the previous comment

  • That’s right, @Maisonsakamoto!! In this case I wanted the second banner to disappear too. But it has helped A lot. Thanks guys.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.