kwangbul
kwangbul

Reputation: 41

Can I use Javascript to get a web page Without the use of XMLHttpRequest or document object?

web server send HTML(1) ---> Browser get the HTML(1) ---> script engine starts to work and so on..

I need to get a HTML(1) in my project. 'XMLHttpRequest.responseText' can do it. I think it's great! But it have to make an another request.

And 'document.getElementsByTagName()' return a rendered HTML. It's not that I want.

we can see the HTML(1) in 'script' tab on IE developer tool.(not 'html' tab) Then I guess that it could be possible to get HTML(1) without another request.

Is there any way to get the HTML(1) with javascript?

Added----------------------------- there is sample.html

<script>
    document.write('AAAAAA');
</script>
<body>
body content
</body>

document.getElementsByTagName('html') return like following.

<script>
    document.write('AAAAAA');
</script>
<body>
AAAAAAbody content
</body>

But I need... pure source of the web page

Upvotes: 1

Views: 330

Answers (1)

Musa
Musa

Reputation: 97672

If you want to get the current page as a string use document.documentElement.innerHTML


I don't think browsers actually keep the original HTML which was sent by web server, because if you try to view a page source the browser actually makes a request to the server.

Upvotes: 3

Related Questions