Empty page using jQuery

Hello

Is there a way through jQuery of JS in general to totally empty the output of a browsed document?
That means removing the whole <html> children along to what could come above the <html> tag?

Thank you

You should then look into PHP’s output buffering mechanism. You might have to wrap things in an extra layer of PHP files, but it shouldn’t be impossible.

Using [fphp=ob_clean]ob_clean()[/fphp] you could clean the output buffer after the ‘magic’ line.

Hello,

I agree with you on that, but I have #!/usr/bin/php -q (it is needed for something) on the top of my PHP file, and I need to remove this line when executing the file through the browser.

I guess this will only remove the the html children not everything (assumingly i have something like


xyz <html>....</html>

I’m trying to use the $(document).empty(); which is working perfectly; however there is a problem.

What I have is as follows:

  1. PHP file runs, echoes something
  2. JS clears output at the beginning
  3. PHP output text later in the file

the problem is, the empty is clearning everything, so whatever is to be outputted is removed too because it is executing at a later stage it seems.

So the question now is, how can I let it run on an event such as it clears before the document is ready allowing further text to be output, or how can I select what is around the HTML tag? (I need to remove some text that is being output before my actual html).

$(‘whatisaroundthehtml’).empty();

thank you

var html = document.documentElement;
while (html.hasChildNodes()) {
    html.removeChild(html.firstChild);
}

You can’t. That’s invalid HTML, and since the <html> start tag and the </html> end tag (plus those for head and body) are optional, browsers will interpret that as,

<html>
  <head></head>
  <body>
    xyz
    <html>....</html>
  </body>
</html>

The ‘outer’ HTML element is the document root element, so my code would still work.

There can’t be anything ‘around’ the HTML element. You can have a doctype declaration, SGML comments and, in theory at least, processing directives outside the HTML element, but nothing can wrap around it.

This doesn’t apply for XHTML served as an application of XML, but it does apply for HTML – including pretend-XHTML served as text/html.