inject text from javascript to html “View source”

2019-08-09 07:35发布

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)

标签: view-source
4条回答
等我变得足够好
2楼-- · 2019-08-09 07:44

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

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-08-09 07:55

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.

查看更多
爷、活的狠高调
4楼-- · 2019-08-09 07:56

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.

查看更多
一夜七次
5楼-- · 2019-08-09 07:57

Some techniques:

  1. In some browsers Ctrl-A to select the whole rendered page content and, with a right click View Source of selection, gives the source as generated by rendering scripts. (often <script> elements are gone and replaced by the rendered content)

  2. Augment the address bar URI by prepending view-source: to get the original source.

  3. 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
查看更多
登录 后发表回答