innerHTML set using Javascript is not visible on View Page Source

I am generating dynamic pages on my site using innerHTML (see example below).

<script type="text/javascript">

function load() {
      document.getElementById("content").innerHTML="New Content";


<body onload="load();">
<div id="content">Old content</div>

When I do a "View-Page Source" on the browser (both IE and Firefox), I was expecting to see:
<div id="content">New Content</div>
but instead I see:
<div id="content">Old Content</div>

The Page on the browser, though, display "New Content" correctly. Only the View-PageSource is the problem. Any idea on how to do this so that the "View-PageSource" shows the changed content?

The reason, I ask is because I am expecting Search Engine bots to visit the dynamic pages and if the content that gets displayed to the bots is not the "new content" then my dynamic pages are useless.

Any other way of doing this would also be appreciated.
Who is Participating?
Michel PlungjanIT ExpertCommented:
Yeah, why do you not tell us what you REALLY are doing so we can give better advice?
TimCotteeHead of Software ServicesCommented:
I think the simple answer to this is no.

What you see when you view source is the initial page that is sent by the web server to the client when the page is requested. In other words the relevant markup that renders the first view of the page.

At that point your javascript and anything else takes over (including user-interaction - would you want the page source to show the password just entered into an input element etc) and the page source is not changed.

The reason why you are seeing that is because when the page is rendered the <div id="content">Old Content</div> is placed, then when the body is loaded the browser detects that the function load() should be called and does that which replaces the innerHTML of your DIV using the DOM.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Dumb question: why don't you just render/output the new content in the content-div and replace the old content directly. Only so Search engines will index you page correctly (search engines don't evaluate Javascript).
unmeshmAuthor Commented:
Thanks folks. I guess I will have to rewrite to have the content be generated on the Service side instead of using Javascript. Its an AJAX site hence the heavy reliance on innerHTML. But if the bots are not going to see the dynamic content - javascript is out. Will wait for a few more hours before disbursing the points.
unmeshmAuthor Commented:
mplungian: here is an example URL from my site:

As you can see, when this URL is opened, other neighborhood places show up on the sidebar and they have embedded links in them that I wanted the bot to visit and index. I am filling up the sidebar using Javascript (setting innerHTML). I will look into setting this on the server side.
Michel PlungjanIT ExpertCommented:

Yes if you do not want to gamble that google follows ajax data, you can put the links in a nice table in a <noscript></noscript> tag

I seem to have read something about the danger of sniffing the bot and serve google prechewed pages...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.