• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1612
  • Last Modified:

innerHTML set using Javascript is not visible on View Page Source

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

<script type="text/javascript">

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

</script>

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

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.
0
unmeshm
Asked:
unmeshm
4 Solutions
 
TimCotteeCommented:
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.

0
 
4rcl1t3Commented:
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.
0
 
hernst42Commented:
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).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Michel PlungjanIT ExpertCommented:
Yeah, why do you not tell us what you REALLY are doing so we can give better advice?
0
 
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.
0
 
unmeshmAuthor Commented:
mplungian: here is an example URL from my site: http://www.sadakmap.com/p/Cafe-Coffee-Day/

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.
0
 
Michel PlungjanIT ExpertCommented:
Ahh.

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...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now