Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing whole HTMLinside body tag

I want to replace the whole HTML inside body tag with some content and I use these codes inside both head and body sections, but in the fist code it doesn't show the content and in the second code it shows the content but doesn't clear ex-content.

the first code:

<script>

var content = 'some content';

if(navigator.appName=="Netscape")
{
document.getElementsByTagName('body').innerHTML = content; 
}

</script>

the second code:

<script>

var content = 'some content';

if(navigator.appName=="Netscape")
{
document.body.innerHTML = content; 
}

</script>

also I use some php code in the document

what should I do?
thanks

like image 561
user1749030 Avatar asked Sep 05 '25 03:09

user1749030


2 Answers

.getElementsByTagName returns an array so you have to use [0] to get the first element:

<script type="text/javascript">

    var content = 'some content';
    document.getElementsByTagName('body')[0].innerHTML = content; 

</script>

Here is an example: http://jsfiddle.net/MWjsc/

like image 182
Laurence Avatar answered Sep 07 '25 21:09

Laurence


I believe that you want to display some special content like browser not supported for netscape.

You can use document.write document.write(content); this will replace total document content.

like image 34
San Avatar answered Sep 07 '25 19:09

San