tags:

views:

68

answers:

6

For example, I use:

$('test-div').html("<div></div>")

Actually the html is changed, but when I click "view source" from the browser, in browser the html is not changed, is it a bug for the browser?

Thanks.

+2  A: 

View source pulls the results directly from the server and does not run any javascript.

Therefore your .html() call did not get run.

Flash84x
@Flash84x, This is wrong, the `html()` call ran fine, but it doesn't change the file's contents.
Jacob Relkin
@Jacob Relkin: His `.html()` call did not run in the view-source window.
Christian Mann
@Christian Yes, that is what I was referring to.
Flash84x
+2  A: 

'View Source' always shows the HTML source of the file when it was downloaded originally. Updates via jQuery/Ajax will never show up there.

Andrew Barber
Interesting sidenote to that: Chrome's view source opens it up in a new tab, which is great and all, *except* that it gets the page afresh from the server. If the web site is set up in a certain way, it might not reflect what you have on your screen at all.
Christian Mann
I swore that's what Chrome was doing one day a while ago, but it wasn't a big deal at the time and I didn't look further into it. +1 for mentioning that!
Andrew Barber
+4  A: 

This is because this changes the HTML (actually the DOM) that is seen by the browser at runtime, not the actual source of the page.

Let's say for the sake of argument that using .html() actually could change the actual source of the page, don't you think this might raise a security concern or two? Or three?

The answer is no, you cannot change the source of a web page from JavaScript without first tunneling through the server side via Ajax or other means.

Jacob Relkin
Maybe even four :P +1
alex
@alex: Don't get too wild here.
Christian Mann
+6  A: 

No... when you view source you are looking at what was actually sent as the HTTP Response from the server. When using JQuery you are manipulating the DOM, which is an in-memory representation of the rendered page.

Josh
+3  A: 

View Source gives You the source of the page that was initial to all changes by jquery the dynamic changes are reflected in the generated source chk out the Web Developer plugin for firefox

Edit : https://addons.mozilla.org/en-US/firefox/addon/60/

view source > view Generated source

jknair
+1  A: 

View source feature give you source in html who they obtained from server he not show you changes even if you update and modified the content using ajax or jquery

but you can also find out changes by plugin or add-ons like Firebug or Web Developer.

the source you see using View source not show you all changes who you made by jquery or ajax. he just show you content who they obtain from server.

steven spielberg