• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print javascript variable

 
Sonal Jogi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a variable and i want to print its value as comment (not front end), so that the value can only be checked in view source. Its something like this:
document.write("<!-- No of links Received = "+ google_ads.length+ "-->");
But in this case, when we do view source, we are able to simply see the same statement and not the actual value of google_ads.length. Could anyone please help?

Thanks in advance,
sonal
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you are not going to see the stuff on the screen, that is the way that it works. It is not like a server side code with a Response.write, the server puts that in the page as it renders, client side code basically puts it into memory.

if you want to see the stuff on the screen you need type this into your address bar:

javascript:alert(document.body.innerHTML);

Eric
 
Sonal Jogi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,

U r absolutely right in that but i dont want to print it on screen. Its for validation purposes that i have to log the length of the array as html comment. But in the above case when i do a view source, i see the same sattement whereas i want it to be like document.write("<!-- No of links Received = "+ 10 + "-->"); where 10 is the actual length of the array.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The view source is grabbing the document from cache not the source, there is no way for you to see the value that the page renders.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic