W
W
WQP2014-08-02 17:45:41
JavaScript
WQP, 2014-08-02 17:45:41

How to download the source code of a page?

Hello, it is necessary that when the page is loaded, the code is simultaneously loaded into the JS variable, and then displayed in the code. How to do this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Petrov, 2014-08-03
@Petroveg

The JS interpreter cannot start before the parser starts processing the code, and you will not get the source code exactly as it is. The script in respected @iiil 's example will only be able to get the re-serialized result of source code deserialization. For example, the result for IE8 for this example is:

Какой-то код
<HEAD><META content="IE=8.0000" http-equiv="X-UA-Compatible">

<META charset=UTF-8>
<META name=robots content=noindex><LINK href="http://codepen.io/iiil/pen/qtFpr" rel=canonical>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>Какой-то код</DIV><PRE></PRE>
<SCRIPT src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></SCRIPT>

It is clear that it is clearly not worth relying on the coincidence of the real source code and what it turned into as a result of a double operation. And most importantly, the meaning of the action is not entirely clear.

O
Oleg Voitenko, 2014-08-02
@OliverV

the question is not entirely clear. Where will the code go into the variable?

Y
Yuri Lobanov, 2014-08-03
@iiil

codepen.io/iiil/pen/qtFpr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question