When I change text using JavaScript The text does not appear in the HTML "View source". Is it possible to inject information to the HTML "View source". (When I write View source I mean to While you pressing on the right mouse button in the browser you can view the source code That returns from the server)
问题:
回答1:
View Source shows you only the HTML it received from the server's response. Your JS changes happen afterward.
Firebug and Chrome's debugger show you the source dynamically so you can see the DOM and HTML as it has been changed. But view source will only ever show you what the browser received from the server.
回答2:
Well,
You have said it right. When you "View source" you see what was received from the server, and elements that you added dynamically using javascript do not exist there.
If you want to see elements which you added later, you can do that using Inspect element (CTRL + SHIFT + I), which will show you current html structure displayed in browser.
回答3:
When you "view source" in a browser, it is opening a window and printing the source code to the current page. This text is totally static, nothing will change its contents besides manually refreshing.
If you want the HTML source you are looking at to reflect changes you make to the page, you need to use your browsers Dev Tools. Try Right Click->Inspect Element instead of Right Click->View Source
回答4:
Some techniques:
In some browsers
Ctrl-A
to select the whole rendered page content and, with a right clickView Source
of selection, gives the source as generated by rendering scripts. (often<script>
elements are gone and replaced by the rendered content)Augment the address bar URI by prepending
view-source:
to get the original source.Use the menu bar or right click
View Source
interfaces.
With these techniques and FF it is possible to get different sources for a "static" page in the rendering chronology.
Technique #1 is interesting when automated ... along the lines of:
- generate a page that displays the time in seconds,
- select whole page,
- render the source view of the selection
- repeat periodically
quasi code:
setInterval ( write Date() to page, select all, write view source of selection to page ) every second