简体   繁体   中英

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).

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

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>"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM