Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript conditionally hide an element when entering 404-page.

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #164132
    twincy
    Participant

    since the url doesn’t change i can’t conditionally hide the element with, for example:

    // hide header if url contains "#dest"
        if (window.location.href.indexOf("#dest") != -1) {
            $("header").hide();
        }
    

    …which works nicely on all other pages.

    any ideas of another condition that could be met to pull it off? perhaps something with php instead? can i set something in .htaccess so the /404.php would show in the url instead of keeping the erroneous url the user accidentially typed? if so, i could easily target that condition.

    #164152
    twincy
    Participant

    ok. got it.

    on the 404-page i put:

    <script>var pagenotfound = true;</script>
    

    and in my js-file i put:

    if (pagenotfound==true) { $('header').hide();  }
    

    boom!

    #164238
    twincy
    Participant

    hmm… but since i’m using php includes the body-element of the document is in the included header and is not unique to the 404 page…

    how can i work around that?

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.