I need to fetch body tag from the url which i open. I am using following code but it is not working. Please suggest.
document.getElementsByTagName('body')[0].innerHTML;
Thanks Tanu
I need to fetch body tag from the url which i open. I am using following code but it is not working. Please suggest.
document.getElementsByTagName('body')[0].innerHTML;
Thanks Tanu
Copy below code in url navigation bar. See, whole body content alerted.
javascript:(alert(document.body.innerHTML));
Its means you can get the body content by just body.innerHTML. you don't require to use getElementsByTagName.
Did you try document.body.innerHTML?
Here is my simple test
<html>
<head>
<title>TEST </title>
<script type="text/javascript">
MyFunction = function () {
alert(document.body.innerHTML);
};
</script>
</head>
<body onload="MyFunction();">
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
it's working on FF
Assuming that:
That that will work, although it is uglier than document.body.innerHTML
.