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
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
- 4 Is this a joke? Are you writing code for extinct browsers, or what? – Jukka K. Korpela Commented Oct 22, 2012 at 12:50
- 2 Looks like some W3Schools example code to me :) – Laurence Commented Oct 22, 2012 at 12:51
- Don't use browser detection at all; try to use feature detection instead. – feeela Commented Oct 22, 2012 at 12:52
- what is the problem with the above code? – JSK NS Commented Oct 22, 2012 at 13:08
- honestly, you shouldn't do anything, I don't think Netscape is used anymore. – BBog Commented Oct 22, 2012 at 13:44
3 Answers
Reset to default 14.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.
Get fancy:
document.documentElement.innerHTML = document.implementation.createHTMLDocument().documentElement.outerHTML
// <html><head></head><body></body></html>