user3848973
user3848973

Reputation: 19

getting the contents of a html page using javascript

As when i scroll down the mouse more content are loaded in html page?Is there any way that i can access all this content without scrolling down the mouse using javascript?

var contents  = document.getElementsByTagName("div")

this code give div of a html page(without scrolling).

Upvotes: 0

Views: 75

Answers (3)

Florian Gl
Florian Gl

Reputation: 6014

It depends on how the content is loaded. If its just invisible, you can get it this way. But in most cases the content is loaded dynamically, means if the user scrolls to some point, the page sends an ajax request for more content to the server. When the server sends back the data, javascript updates the page. In this case you can't do anything, because it's not possible to send cross-domain ajax-requests.

Upvotes: 0

Clément Andraud
Clément Andraud

Reputation: 9269

You want to access content that is not loaded? You can't...

Upvotes: 1

Justinas
Justinas

Reputation: 43479

Use innerHtml:

contents = document.getElementsByTagName("div");
console.log(contents[0].innerHTML);

Or if you are using jQuery, add some ID to that div, that you want it's content:

<div id='divId'>Hello <span>World</span></div>

$('#divId').text(); // Will return "Hello World"
$('#divId').html(); // Will return "Hello <span>World</span>"

Upvotes: 0

Related Questions