gruber
gruber

Reputation: 29729

hide everything on site

Is it possible to hide everything on site using jquery before it starts to be rendered ? I check query string and if something is as I expected I do postback and then want to render correct site content.

Upvotes: 0

Views: 149

Answers (4)

PeeHaa
PeeHaa

Reputation: 72672

What I would do is the following:

  • Start the page without any content but an AJAX loader.
  • Check the query string and let it return either the html or an object which states query string is invalid
  • if valid load html in dom
  • if invalid notify user

This way prevents users to see the content even if query string is invalid because they have disabled javascript.

Also just hiding stuff is bad, because users can just manipulate the DOM to show the elements.

Upvotes: 1

Jamie
Jamie

Reputation: 1014

You would be better to just hide the body by default then do your postback and after that append a class with a style of 'display:block;' - otherwise as javascript isn't loaded straight away, you may get a flash where it loads and then hides.

Upvotes: 2

Nebril
Nebril

Reputation: 3273

You can use $('body').hide(), change body tag content with $('body').hide(content) and then use $('body').show().

Upvotes: 1

Alex
Alex

Reputation: 35409

In the head you could do the following...

<head>
...

<script>$(function() { $(document.body).show(); });</script>

...
</>

In the body you can have the following...

<body>
   <script>document.body.style.display = 'none';</script>


   ...

</body>

Using this approach will not produce a flash on the page...

Upvotes: 1

Related Questions