View Full Version : document.write SEO question

11-30-2007, 03:22 PM
Can search engines read document.write()? I believe it can read the Php "echo", correct? Which one would be the best?

11-30-2007, 05:02 PM
ASP and PHP both happen on the server side before the page is delivered to the user agent. SE's don't know or care how you create the HTML that they end up reading.

12-01-2007, 04:47 AM
yes...but as javascript is client-side, SEs wont read it would they?

12-01-2007, 08:31 AM
Yes just because Javascript is client side, so what you (visitor) read on the browse is the content that document.write() write out. But SEs and another spiders will get only document.write() statement.

12-01-2007, 03:20 PM
Alright! Thanks nothinglastz and pennimus!

12-01-2007, 08:43 PM
Anything that can be done with document.write can also be done server side. If you have a server side language available to you then use that and forget the antiquated unnecessary JavaScript document.write statement.

12-01-2007, 08:57 PM
I wouldn't call it antiquated and unnecessary....but i definately see your point, and I will use the PHP echo instead of document.write.

12-01-2007, 09:03 PM
This is very interesting...I should have checked this in the very first place, but I didn't think of it. I googled my site and checked google's cache of it, and surprisingly it displayed my menu in the cache, although I have my menu written all the way from a completely external javascript. Does this mean google can read document.write?

12-01-2007, 11:30 PM
I wouldn't call it antiquated and unnecessary....but i definately see your point, and I will use the PHP echo instead of document.write.

The limitations on where you can use document.write mean that it can only be used where a server side script could have generated the content instead and done so even where JavaScript is disabled. Since using a server side script is always the better choice than using document.write it is therefore only necessary where the web page doesn't have access to use server side scripting and since all paid hosting has server side scripting that means that it would only ever be necessary for some free hosting.

Where you do want JavaScript to write to your page then the best way to do it is to use the Document Object Model commands that are there specifically for that purpose. They will always work provided that JavaScript is enabled.

If you don't want to use the DOM and do it according to the standards then you can use innerHTML which is supported by all modern browsers and will also work as long as JavaScript is enabled and the page uses HTML (not XHTML).

document.write doesn't only not work when JavaScript is not enbled, it also doesn't work once the web page finishes loading and it doesn't work if the page uses XHTML instead of HTML.

Anywhere that you can use document.write you could use server side processing. If server side processing is not available then anywhere you can use document.write you can use innerHTML or the DOM instead and achieve better separation between your HTML and JavaScript.

document.write is therefore completely unnecessary and antiquated as it does not support the latest standards in how you should write your HTML and JavaScript.

The only real use that document.write has had over the last five or so years since its use in proper JavaScripts became obsolete is as a simple way of outputing the result of running JavaScript code for people learning how to write JavaScript. Once they are half way through learning how to code JavaScript and learn about innerHTML and the DOM then they can and should completely forget about document.write.

Using document.write in a script is an indication that either the person who wrote the script does not really know how to write JavaScript OR the script was written several years ago and really ought to be rewritten to modern standards.