Own the whole question in the title.

Closed due to the fact that the essence of the issue is not clear to the participants of Darth , Igor , Sergey Gornostaev , andreymal , Cheg 4 Oct '17 at 0:28 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What is meant by "through jS"? And for what? - D-side
  • For example, I have a VK widget on the page. It is necessary after its drawing, to parse the user id. - Rinat Audi
  • Will not work. Same Origin Policy will not give. - D-side

2 answers 2

To get the content of an element in plain text, the elements have an InnerHTML property.

let elem = document.getElementTagName('Body')[0]; text = elem.innerHTML console.log(text); 

Since the getElementTagName method returns an HTMLCollection, and this is an object like an array, we need to refer to it by index.

Accordingly, in order to change the content of the element, it is necessary to assign a new value to this property.

  • Thank you. The content of the iframe is not displayed only, although everything in the code of the page can be read. - Rinat Audi
  • The point is that the iframe object is represented by another execution context. It is a separate window object that can be referenced by its window.frames [ID] identifier, but if the parent document and the child document are of different origin, then the scripts will not be able to interact with each other due to the policy of common origin. Theoretically, the contents of the child frame can be obtained as text = window.frames ['ID']. Document.getElementByTagName ('body') [0] .innerText - user268178
  • Body is not the whole page. better to take 'html' - Darth
  • text = window.frames ['vkwidget1']. document.getElementById ('ee'). ‌ innerText; console.log (text); did so, in the console issued the following: GET top-fwz1.mail.ru/js/code.js net :: ERR_BLOCKED_BY_CLIENT - Rinat Audi

 console.log([...document.childNodes].map(node => node.innerHTML).join())