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
.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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With